Skip to content

Commit

Permalink
Check array length in collapseArrayExpressions
Browse files Browse the repository at this point in the history
- Check that the length of the array actually matches the number of
  elements in the array that the cref represents.
  • Loading branch information
perost committed Feb 25, 2021
1 parent d037f28 commit b7ab7fc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions OMCompiler/Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -871,7 +871,7 @@ protected
DAE.Type ty;
list<DAE.Dimension> dims;
list<Integer> ds;
Integer len;
Integer len, exp_count;
list<DAE.Exp> exps;
DAE.Exp exp1;
Absyn.Ident call1, call2;
Expand Down Expand Up @@ -911,8 +911,15 @@ algorithm
for sub in subs loop
DAE.INDEX(DAE.ICONST(1)) := sub;
end for;

// Same number of expressions as expected...
true := (1+listLength(exps))==len;
exp_count := listLength(exps) + 1;
true := exp_count == len;

// Check that the number of expressions matches the size of the array the cref represents.
dims := Types.getDimensions(ComponentReference.crefLastType(cr1));
true := exp_count == product(i for i in Expression.dimensionsSizes(dims));

for exp in exps loop
//DAE.CREF(componentRef=cr2) := exp;
(cr2, call2) := match exp
Expand Down

0 comments on commit b7ab7fc

Please sign in to comment.