Skip to content

Commit e399bfc

Browse files
sjoelundclaude
andauthored
MM frontend: fix uninit-output bugs (#15662)
* Expression.addVec was unused (only Expression.subVec is called from ResolveLoops.mo). Remove addVec; the early-\`return;\` in its body reads back an uninitialised output array. * Expression.subVec hit the same uninit-output bug on the size-mismatch path. Replace \`return;\` with \`fail();\` so an error message at the caller surfaces, matching the function's documented behaviour. * Static.elabExp_If: rewrote the inner \`_ := matchcontinue()\` to return its values directly via \`(outCache, outExp, outProperties) := matchcontinue() … then (outCache, outExp, outProperties); \`. Returning the values explicitly makes the data flow direct and easier to analyze. * Static.deduceIterationRange: initialise \`outRange\` and \`outProperties\` with neutral sentinels (\`DAE.ICONST(0)\` / \`DAE.PROP(T_UNKNOWN_DEFAULT, C_UNKNOWN)\`) to make the analysis easier. (It was safe before, just hard to prove) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 62ac102 commit e399bfc

2 files changed

Lines changed: 7 additions & 25 deletions

File tree

OMCompiler/Compiler/FrontEnd/Expression.mo

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4159,24 +4159,6 @@ public function lenVec
41594159
len := Expression.makePureBuiltinCall("sqrt",{len},DAE.T_REAL_DEFAULT);
41604160
end lenVec;
41614161

4162-
public function addVec
4163-
input array<DAE.Exp> v;
4164-
input array<DAE.Exp> w;
4165-
output array<DAE.Exp> y;
4166-
4167-
protected
4168-
Integer size1=arrayLength(v), size2= arrayLength(w);
4169-
algorithm
4170-
if size1 <> size2 then
4171-
print("addVec fail.\n");
4172-
return ;
4173-
end if;
4174-
y := arrayCreate(size1, DAE.RCONST(0.0));
4175-
for i in 1:size1 loop
4176-
arrayUpdate(y,i,expAdd(arrayGet(v,i), arrayGet(w,i)));
4177-
end for;
4178-
end addVec;
4179-
41804162
public function subVec
41814163
input array<DAE.Exp> v;
41824164
input array<DAE.Exp> w;
@@ -4186,8 +4168,8 @@ protected
41864168
Integer size1=arrayLength(v), size2= arrayLength(w);
41874169
algorithm
41884170
if size1 <> size2 then
4189-
print("addVec fail.\n");
4190-
return ;
4171+
print("subVec fail.\n");
4172+
fail();
41914173
end if;
41924174
y := arrayCreate(size1, DAE.RCONST(0.0));
41934175
for i in 1:size1 loop

OMCompiler/Compiler/FrontEnd/Static.mo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ algorithm
479479
(cache, cond_exp, cond_prop) := elabExpInExpression(inCache,
480480
inEnv, cond_e, inImplicit, inDoVect, inPrefix, inInfo);
481481

482-
_ := matchcontinue()
482+
(outCache, outExp, outProperties) := matchcontinue()
483483
case ()
484484
algorithm
485485
ErrorExt.setCheckpoint("Static.elabExp:IFEXP");
@@ -492,7 +492,7 @@ algorithm
492492
inPrefix, inInfo);
493493
ErrorExt.delCheckpoint("Static.elabExp:IFEXP");
494494
then
495-
();
495+
(outCache, outExp, outProperties);
496496

497497
case ()
498498
algorithm
@@ -505,7 +505,7 @@ algorithm
505505
ErrorExt.delCheckpoint("Static.elabExp:IFEXP:HACK");
506506
ErrorExt.rollBack("Static.elabExp:IFEXP");
507507
then
508-
();
508+
(outCache, outExp, outProperties);
509509

510510
else
511511
algorithm
@@ -1486,8 +1486,8 @@ public function deduceIterationRange
14861486
input FCore.Graph inEnv;
14871487
input FCore.Cache inCache;
14881488
input Absyn.Info inInfo;
1489-
output DAE.Exp outRange;
1490-
output DAE.Properties outProperties;
1489+
output DAE.Exp outRange = DAE.ICONST(0);
1490+
output DAE.Properties outProperties = DAE.PROP(DAE.T_UNKNOWN_DEFAULT, DAE.C_UNKNOWN());
14911491
output FCore.Cache outCache = inCache;
14921492
protected
14931493
Absyn.ComponentRef acref;

0 commit comments

Comments
 (0)