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

Commit 090346b

Browse files
Willi BraunOpenModelica-Hudson
authored andcommitted
[BE] added debug flag to enable error asserts from min/max attributes
- debug flag warnMinMax is default to true, because the desired behavior is an error assert - also check min/max assert in the initialization - fixing ticket:4985 Belonging to [master]: - #2676 - OpenModelica/OpenModelica-testsuite#1040
1 parent 0cdd3ea commit 090346b

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Compiler/BackEnd/BackendVariable.mo

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ public function getMinMaxAsserts "author: Frenkel TUD 2011-03"
18711871
algorithm
18721872
outAsserts := matchcontinue(inVar)
18731873
local
1874-
DAE.Exp e, cond, msg;
1874+
DAE.Exp e, cond, msg, level;
18751875
Option<DAE.Exp> min, max;
18761876
String str, varStr, format;
18771877
DAE.Type tp;
@@ -1897,11 +1897,17 @@ algorithm
18971897
false = Expression.isConstTrue(cond);
18981898
str = getMinMaxAsserts1Str(min, max, ComponentReference.printComponentRefStr(name));
18991899

1900+
if Flags.isSet(Flags.WARNING_MINMAX_ATTRIBUTES) then
1901+
level = DAE.ASSERTIONLEVEL_WARNING;
1902+
else
1903+
level = DAE.ASSERTIONLEVEL_ERROR;
1904+
end if;
1905+
19001906
// if is real use %g otherwise use %d (ints and enums)
19011907
format = if Types.isRealOrSubTypeReal(tp) then "g" else "d";
19021908
msg = DAE.BINARY(DAE.SCONST(str), DAE.ADD(DAE.T_STRING_DEFAULT), DAE.CALL(Absyn.IDENT("String"), {e, DAE.SCONST(format)}, DAE.callAttrBuiltinString));
1903-
BackendDAEUtil.checkAssertCondition(cond, msg, DAE.ASSERTIONLEVEL_WARNING, ElementSource.getElementSourceFileInfo(source));
1904-
then DAE.ALGORITHM_STMTS({DAE.STMT_ASSERT(cond, msg, DAE.ASSERTIONLEVEL_WARNING, source)})::inAsserts;
1909+
BackendDAEUtil.checkAssertCondition(cond, msg, level, ElementSource.getElementSourceFileInfo(source));
1910+
then DAE.ALGORITHM_STMTS({DAE.STMT_ASSERT(cond, msg, level, source)})::inAsserts;
19051911

19061912
else inAsserts;
19071913
end matchcontinue;

Compiler/Util/Flags.mo

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ constant DebugFlag NF_API = DEBUG_FLAG(182, "nfAPI", false,
540540
Util.gettext("Enables experimental new instantiation use in the OMC API."));
541541
constant DebugFlag FMI20_DEPENDENCIES = DEBUG_FLAG(183, "disableFMIDependency", false,
542542
Util.gettext("Disables the dependency analysis and generation for FMI 2.0."));
543+
constant DebugFlag WARNING_MINMAX_ATTRIBUTES = DEBUG_FLAG(184, "warnMinMax", true,
544+
Util.gettext("Makes a warning assert from min/max variable attributes instead of error."));
543545

544546
// This is a list of all debug flags, to keep track of which flags are used. A
545547
// flag can not be used unless it's in this list, and the list is checked at
@@ -729,7 +731,8 @@ constant list<DebugFlag> allDebugFlags = {
729731
NF_EVAL_CONST_ARG_FUNCS,
730732
NF_EXPAND_OPERATIONS,
731733
NF_API,
732-
FMI20_DEPENDENCIES
734+
FMI20_DEPENDENCIES,
735+
WARNING_MINMAX_ATTRIBUTES
733736
};
734737

735738
public

SimulationRuntime/c/simulation/solver/initialization/initialization.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,9 @@ int initialization(DATA *data, threadData_t *threadData, const char* pInitMethod
731731
printZeroCrossings(data, LOG_EVENTS);
732732
#endif
733733

734+
/* Check for warning of variables out of range assert(min<x || x>xmax, ...)*/
735+
data->callback->checkForAsserts(data, threadData);
736+
734737
/* valid system for the first time! */
735738
TRACE_POP
736739
return retVal;

0 commit comments

Comments
 (0)