Skip to content

Commit 6b77d0e

Browse files
authored
Fix uninitialized variable in EvalConstants (#9062)
1 parent ccee9b0 commit 6b77d0e

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

OMCompiler/Compiler/NFFrontEnd/NFEvalConstants.mo

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ protected
173173
Type ty, ty2;
174174
Variability var;
175175
algorithm
176-
outExp := match exp
176+
(outExp, outChanged) := match exp
177177
case Expression.CREF()
178178
algorithm
179179
(outExp as Expression.CREF(cref = cref, ty = ty), outChanged) :=
@@ -194,16 +194,12 @@ algorithm
194194
outExp := Expression.setType(ty2, outExp);
195195
end if;
196196
then
197-
outExp;
197+
(outExp, outChanged);
198198

199199
case Expression.ARRAY(literal = true)
200-
then exp;
200+
then (exp, false);
201201

202-
case Expression.IF()
203-
algorithm
204-
(outExp, outChanged) := evaluateIfExp(exp, info);
205-
then
206-
outExp;
202+
case Expression.IF() then evaluateIfExp(exp, info);
207203

208204
// TODO: The return type of calls can have dimensions that reference
209205
// function parameters, and thus can't be evaluated. This should be
@@ -213,10 +209,22 @@ algorithm
213209
(outExp, outChanged) := Expression.mapFoldShallow(exp,
214210
function evaluateExpTraverser(info = info), false);
215211
then
216-
outExp;
212+
(outExp, outChanged);
217213

214+
// Only evaluate the index for size expressions.
218215
case Expression.SIZE()
219-
then Expression.SIZE(exp.exp, evaluateExpOpt(exp.dimIndex, info));
216+
algorithm
217+
if isSome(exp.dimIndex) then
218+
SOME(e) := exp.dimIndex;
219+
(e, outChanged) := Expression.mapFoldShallow(e,
220+
function evaluateExpTraverser(info = info), false);
221+
222+
if outChanged then
223+
exp.dimIndex := SOME(e);
224+
end if;
225+
end if;
226+
then
227+
(exp, outChanged);
220228

221229
case Expression.RANGE()
222230
algorithm
@@ -230,7 +238,7 @@ algorithm
230238
outExp := Expression.retype(outExp);
231239
end if;
232240
then
233-
outExp;
241+
(outExp, outChanged);
234242

235243
else
236244
algorithm
@@ -240,7 +248,7 @@ algorithm
240248
ty := Expression.typeOf(outExp);
241249
ty2 := evaluateType(ty, info);
242250
then
243-
if referenceEq(ty, ty2) then outExp else Expression.setType(ty2, outExp);
251+
(if referenceEq(ty, ty2) then outExp else Expression.setType(ty2, outExp), outChanged);
244252
end match;
245253

246254
outChanged := changed or outChanged;

0 commit comments

Comments
 (0)