Skip to content

Commit

Permalink
Warnings for aliases during codegen
Browse files Browse the repository at this point in the history
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]:
  - OpenModelica/OMCompiler#2076
  - OpenModelica/OpenModelica-testsuite#810
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jan 3, 2018
1 parent 47aad95 commit eca7e56
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -566,7 +566,6 @@ protected
end if;
res := (true,SimCodeUtil.getFunctionIndex());
else
ErrorExt.moveMessagesToParentThread();
end try;
end runTplWriteFile;

Expand All @@ -581,7 +580,6 @@ protected
Tpl.tplCallWithFailErrorNoArg(func);
res := (true,SimCodeUtil.getFunctionIndex());
else
ErrorExt.moveMessagesToParentThread();
end try;
end runTpl;

Expand All @@ -599,7 +597,6 @@ protected
func();
res := (true,SimCodeUtil.getFunctionIndex());
else
ErrorExt.moveMessagesToParentThread();
end try;
end runToStr;

Expand All @@ -611,7 +608,10 @@ protected
algorithm
(res as (b,_)) := func();
if not b then
print(System.dladdr(func) + " failed\n");
Error.addInternalError(System.dladdr(func) + " failed\n", sourceInfo());
end if;
if ErrorExt.getNumMessages() > 0 then
ErrorExt.moveMessagesToParentThread();
end if;
end runCodegenFunc;

Expand Down
39 changes: 26 additions & 13 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -399,29 +399,29 @@ algorithm
if debug then execStat("simCode: createModelInfo and variables"); end if;

//build labels
if(boolAnd(ifcpp,Flags.getConfigBool(Flags.LABELED_REDUCTION))) then
Flags.setConfigBool(Flags.GENERATE_LABELED_SIMCODE,true);
if(boolAnd(ifcpp,Flags.getConfigBool(Flags.LABELED_REDUCTION))) then
Flags.setConfigBool(Flags.GENERATE_LABELED_SIMCODE,true);
end if;

if(ifcpp) then
if Flags.getConfigBool(Flags.GENERATE_LABELED_SIMCODE) then
if(ifcpp) then
if Flags.getConfigBool(Flags.GENERATE_LABELED_SIMCODE) then
(allEquations,modelInfo) := ReduceDAE.buildLabels(allEquations,modelInfo,{},args);
//Flags.set(Flags.REDUCE_DAE,true);
if debug then execStat("ReduceDAE: buildLabels"); end if;
end if;
end if;
if debug then execStat("ReduceDAE: buildLabels"); end if;
end if;
end if;

tmpSimVars := modelInfo.vars;

//reduce terms
if(ifcpp) then
if Flags.getConfigBool(Flags.REDUCE_TERMS) then
if(ifcpp) then
if Flags.getConfigBool(Flags.REDUCE_TERMS) then
(allEquations,modelInfo) := ReduceDAE.reduceTerms(allEquations,modelInfo,args);
Flags.setConfigBool(Flags.REDUCE_TERMS, false);
_:=Flags.disableDebug(Flags.REDUCE_DAE);
if debug then execStat("ReduceDAE: reduceTerms"); end if;
end if;
end if;
Flags.disableDebug(Flags.REDUCE_DAE);
if debug then execStat("ReduceDAE: reduceTerms"); end if;
end if;
end if;
// external objects
extObjInfo := createExtObjInfo(shared);

Expand Down Expand Up @@ -13319,6 +13319,19 @@ algorithm
case (cref, SimCode.SIMCODE(crefToSimVarHT = crefToSimVarHT) )
equation
sv = BaseHashTable.get(cref, crefToSimVarHT);
sv = match sv.aliasvar
case SimCodeVar.NOALIAS() then sv;
/* The C++ runtime generates a different set of variables... */
case _ guard Config.simCodeTarget() == "Cpp" then sv;
case SimCodeVar.ALIAS(varName=cref)
algorithm
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);
then cref2simvar(cref, simCode);
case SimCodeVar.NEGATEDALIAS(varName=cref)
algorithm
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);
then fail();
end match;
then sv;

case (_, _)
Expand Down

0 comments on commit eca7e56

Please sign in to comment.