Opened 11 years ago
Closed 11 years ago
#2286 closed defect (fixed)
bad code generation for arrays (2)
Reported by: | Lennart Ochel | Owned by: | Mahder Alemseged Gebremedhin |
---|---|---|---|
Priority: | blocker | Milestone: | 1.9.0 |
Component: | Code Generation | Version: | trunk |
Keywords: | Cc: |
Description
Bad simulation code gets generated for the example bug_2286 from our testsuite.
location: /testsuite/simulation/modelica/algorithms_functions/bug_2286.mos
error message
Simulation failed for model: bug_2286 Error: Error building simulator. Build log: gcc-4.4 -falign-functions -march=native -mfpmath=sse -fPIC -I\"/home/lochel/Documents/workspace/OpenModelica/trunk/bui$ bug_2286.c: In function 'eqFunction_3': bug_2286.c:237: error: used struct type value where scalar is required bug_2286.c: In function 'eqFunction_7': bug_2286.c:335: error: used struct type value where scalar is required make: *** [bug_2286.o] Error 1
Change History (9)
comment:1 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 11 years ago
Priority: | high → blocker |
---|
comment:3 by , 11 years ago
Status: | assigned → accepted |
---|
comment:4 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
comment:5 by , 11 years ago
The following example does still not simulate:
model bug_2286 Boolean a[1] = {false}; Boolean b[1] = {true}; Boolean c[1]; algorithm c := a and b; end bug_2286;
output:
bug_2286.c: In function ‘eqFunction_3’: bug_2286.c:240: error: used struct type value where scalar is required bug_2286.c: In function ‘eqFunction_5’: bug_2286.c:329: error: used struct type value where scalar is required
bug_2286.c (line 240 contains the call of copy_boolean_array_data_mem):
/* equation index: 3 type: ALGORITHM c := {false} and {true}; */ static void eqFunction_3(DATA *data) { boolean_array tmp0; boolean_array tmp1; array_alloc_scalar_boolean_array(&tmp0, 1, (modelica_boolean)(0)); array_alloc_scalar_boolean_array(&tmp1, 1, (modelica_boolean)(1)); copy_boolean_array_data_mem(&(tmp0 && tmp1), &$Pc); }
(Maybe this is already mentioned in another ticket?!)
comment:6 by , 11 years ago
This last issue should not have reached the code gneration. It should have been removed by constant evaluation in the front-end somewhere in ceval.
c := {false} and {true};
should have been reduced to
c := {false};
Anyways this issue could have happened for other cases that can not be reduced with constant folding.
It is handled now. Fixed in r16724.
comment:7 by , 11 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
I implemented the same code for the unary 'not' operator in r16727.
Still code is not generated as expected:
model model_bug_2286
Boolean a[1] = {time > 0.4};
Boolean b[1] = {time > 0.5};
Boolean c[1] = {time > 0.6};
Boolean d[1];
Boolean e[1];
Boolean f[1];
Boolean g[1];
algorithm
d:=a and b and c; /* fails */
e:=not (a and b); /* fails */
f:=not a and b; /* fails */
g:=a and not b; /* succeeds */
end model_bug_2286;
comment:8 by , 11 years ago
Your code only looks for CREF and array. But in this case it needs to look for a binary expression. There exists functions so you can match against the type of the expression instead. Or better yet: Match against the type inside the record AND
. Then it will work for any expression.
comment:9 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Fixed in r16756 using the type in the operators instead of the types from the lhs and rhs. It should work fine since there is no operator in modelica that can take boolean arrays and result in boolean scalar and vice versa. If there are more issues we should open a new ticket since the original issue is already fixed.
This should be fixed as soon as possible, because it blocks the Petri net library.