Opened 11 years ago

Closed 11 years ago

#2285 closed defect (fixed)

bad code generation for arrays

Reported by: Lennart Ochel Owned by: Mahder Alemseged Gebremedhin
Priority: blocker Milestone: 1.9.1
Component: Code Generation Version: trunk
Keywords: Cc:

Description

Bad simulation code gets generated for the example bug_2271_b from our testsuite.
location: /testsuite/simulation/modelica/algorithms_functions/bug_2271.mos

error message

Simulation execution failed for model: bug_2271_b
array s->index[0][1] == 4 incorrect, a->dim_size[0] == 3
bug_2271_b: util/real_array.c:322: indexed_assign_real_array: Assertion `index_spec_fit_base_array(dest_spec, dest)' failed.
Aborted (core dumped)

Change History (8)

comment:1 by Adrian Pop, 11 years ago

Lennart, there is no model in directory:
testsuite/simulation/modelica/algorithms_functions/
that starts with b*. Have you forgot to add it?

comment:2 by Adrian Pop, 11 years ago

Sorry, I'm stupid, I did not do svn up :)

comment:3 by Adrian Pop, 11 years ago

Owner: changed from Martin Sjölund to Mahder Alemseged Gebremedhin
Status: newassigned

comment:4 by Mahder Alemseged Gebremedhin, 11 years ago

Status: assignedaccepted

comment:5 by Henning Kiel, 11 years ago

x[1:n]:=fill(0.0,n);

this creates a temporary array t1[2] and makes an (indexed) assign from the fill() to t1 and then copies t1 verbatim to x
=> index starts with "1". The copy procedure is problematic if t1 and x have more than one dimension and dimensions differ.

x[n+1:M]:=fill(1.0,N-n);

this creates a temporary array t2[3] and makes an indexed assign from the fill() to t2 and then copies t2 verbatim to x
=> index starts with 3 and is thus too large for t2
=> later t2 is copied verbatim to x which (a) does not use the index spec and (b) overwrites the content copied from t1 earlier.

temporary arrays should not be filled with index.
When copying the temporary arrays to the destination x, the index should be considered.

template indexedAssign(DAE.Type ty, String exp, DAE.ComponentRef cr,
  String ispec, Context context, Text &varDecls)
::=
  let type = expTypeArray(ty)
  let cref = contextArrayCref(cr, context)
  match context
  case FUNCTION_CONTEXT(__) then
    'indexed_assign_<%type%>(&<%exp%>, &<%cref%>, &<%ispec%>);'
  case PARALLEL_FUNCTION_CONTEXT(__) then
    'indexed_assign_<%type%>(&<%exp%>, &<%cref%>, &<%ispec%>);'
  else
    let tmp = tempDecl("real_array", &varDecls)
    <<
    alloc_<%type%>(&<%tmp%>, 1, size_of_dimension_<%type%>(<%exp%>, 1));
    indexed_assign_<%type%>(&<%exp%>, &<%tmp%>, &<%ispec%>);
    copy_<%type%>_data_mem(&<%tmp%>, &<%cref%>);
    >>
end indexedAssign;

looks like the else part is not correct here, but the other line is

comment:6 by Lennart Ochel, 11 years ago

Priority: highblocker

This blocks the Petri net library.

comment:7 by Martin Sjölund, 11 years ago

Milestone: 1.9.01.9.1

Postponed until 1.9.1

comment:8 by Mahder Alemseged Gebremedhin, 11 years ago

Resolution: fixed
Status: acceptedclosed

=> index starts with 3 and is thus too large for t2

Yes. that was the problem with the assertion failing. Dimensions of the temporary array should be equal to dimensions of the original array NOT the slice.

=> later t2 is copied verbatim to x which (a) does not use the index spec and (b) overwrites the content copied from t1 earlier.

This is also fixed now because we allocate the temporary array itself by copying from the original array. Thereby keeping any previous changes intact.

Fixed in r17741.

Note: See TracTickets for help on using tickets.