Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit eca7e56

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Warnings for aliases during codegen
The code generator gave the wrong variable indexes for aliases that were not replaced in the backend. This prints some warnings or errors for these cases so we can either fix the code (or replace the code generator to handle aliases better). Belonging to [master]: - #2076 - OpenModelica/OpenModelica-testsuite#810
1 parent 47aad95 commit eca7e56

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

Compiler/SimCode/SimCodeMain.mo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ protected
566566
end if;
567567
res := (true,SimCodeUtil.getFunctionIndex());
568568
else
569-
ErrorExt.moveMessagesToParentThread();
570569
end try;
571570
end runTplWriteFile;
572571

@@ -581,7 +580,6 @@ protected
581580
Tpl.tplCallWithFailErrorNoArg(func);
582581
res := (true,SimCodeUtil.getFunctionIndex());
583582
else
584-
ErrorExt.moveMessagesToParentThread();
585583
end try;
586584
end runTpl;
587585

@@ -599,7 +597,6 @@ protected
599597
func();
600598
res := (true,SimCodeUtil.getFunctionIndex());
601599
else
602-
ErrorExt.moveMessagesToParentThread();
603600
end try;
604601
end runToStr;
605602

@@ -611,7 +608,10 @@ protected
611608
algorithm
612609
(res as (b,_)) := func();
613610
if not b then
614-
print(System.dladdr(func) + " failed\n");
611+
Error.addInternalError(System.dladdr(func) + " failed\n", sourceInfo());
612+
end if;
613+
if ErrorExt.getNumMessages() > 0 then
614+
ErrorExt.moveMessagesToParentThread();
615615
end if;
616616
end runCodegenFunc;
617617

Compiler/SimCode/SimCodeUtil.mo

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -399,29 +399,29 @@ algorithm
399399
if debug then execStat("simCode: createModelInfo and variables"); end if;
400400

401401
//build labels
402-
if(boolAnd(ifcpp,Flags.getConfigBool(Flags.LABELED_REDUCTION))) then
403-
Flags.setConfigBool(Flags.GENERATE_LABELED_SIMCODE,true);
402+
if(boolAnd(ifcpp,Flags.getConfigBool(Flags.LABELED_REDUCTION))) then
403+
Flags.setConfigBool(Flags.GENERATE_LABELED_SIMCODE,true);
404404
end if;
405405

406-
if(ifcpp) then
407-
if Flags.getConfigBool(Flags.GENERATE_LABELED_SIMCODE) then
406+
if(ifcpp) then
407+
if Flags.getConfigBool(Flags.GENERATE_LABELED_SIMCODE) then
408408
(allEquations,modelInfo) := ReduceDAE.buildLabels(allEquations,modelInfo,{},args);
409409
//Flags.set(Flags.REDUCE_DAE,true);
410-
if debug then execStat("ReduceDAE: buildLabels"); end if;
411-
end if;
412-
end if;
410+
if debug then execStat("ReduceDAE: buildLabels"); end if;
411+
end if;
412+
end if;
413413

414414
tmpSimVars := modelInfo.vars;
415415

416416
//reduce terms
417-
if(ifcpp) then
418-
if Flags.getConfigBool(Flags.REDUCE_TERMS) then
417+
if(ifcpp) then
418+
if Flags.getConfigBool(Flags.REDUCE_TERMS) then
419419
(allEquations,modelInfo) := ReduceDAE.reduceTerms(allEquations,modelInfo,args);
420420
Flags.setConfigBool(Flags.REDUCE_TERMS, false);
421-
_:=Flags.disableDebug(Flags.REDUCE_DAE);
422-
if debug then execStat("ReduceDAE: reduceTerms"); end if;
423-
end if;
424-
end if;
421+
Flags.disableDebug(Flags.REDUCE_DAE);
422+
if debug then execStat("ReduceDAE: reduceTerms"); end if;
423+
end if;
424+
end if;
425425
// external objects
426426
extObjInfo := createExtObjInfo(shared);
427427

@@ -13319,6 +13319,19 @@ algorithm
1331913319
case (cref, SimCode.SIMCODE(crefToSimVarHT = crefToSimVarHT) )
1332013320
equation
1332113321
sv = BaseHashTable.get(cref, crefToSimVarHT);
13322+
sv = match sv.aliasvar
13323+
case SimCodeVar.NOALIAS() then sv;
13324+
/* The C++ runtime generates a different set of variables... */
13325+
case _ guard Config.simCodeTarget() == "Cpp" then sv;
13326+
case SimCodeVar.ALIAS(varName=cref)
13327+
algorithm
13328+
Error.addSourceMessage(Error.COMPILER_WARNING, {getInstanceName() + " got an alias variable " + ComponentReference.printComponentRefStr(inCref) + " to " + ComponentReference.printComponentRefStr(cref) + ", but before code generation these should have been removed"}, sv.source.info);
13329+
then cref2simvar(cref, simCode);
13330+
case SimCodeVar.NEGATEDALIAS(varName=cref)
13331+
algorithm
13332+
Error.addSourceMessage(Error.INTERNAL_ERROR, {getInstanceName() + " got a negated alias variable " + ComponentReference.printComponentRefStr(inCref) + " to " + ComponentReference.printComponentRefStr(cref) + ", but before code generation these should have been removed"}, sv.source.info);
13333+
then fail();
13334+
end match;
1332213335
then sv;
1332313336

1332413337
case (_, _)

0 commit comments

Comments
 (0)