Opened 4 years ago

Last modified 3 years ago

#6352 accepted defect

Function returning record with array fails

Reported by: Francesco Casella Owned by: Mahder Alemseged Gebremedhin
Priority: high Milestone:
Component: Code Generation Version: v1.17.0-dev
Keywords: Cc: Karim Adbdelhak, Andreas Heuermann, Per Östlund

Description

Please consider this test model (also attached)

model TestFunctionRecordArray
  constant Integer c = 3;

  record R
    Real v;
    Real x[c];
  end R;

  function f
    input Real v;
    output R rout;
  algorithm
    rout.v := v;
    rout.x := {0.3, 0.4, 0.3};
  end f;

  Real x;
  R r;
equation
  x = time;
  r = f(x);
end TestFunctionRecordArray;

The model fails during compilation with

TestFunctionRecordArray_functions.c:33:3: error: 
use of undeclared identifier '_rout'
  _rout._x = _OMC_LIT0;
  ^

Attachments (1)

TestFunctionRecordArray.mo (326 bytes ) - added by Francesco Casella 4 years ago.

Download all attachments as: .zip

Change History (5)

by Francesco Casella, 4 years ago

Attachment: TestFunctionRecordArray.mo added

comment:1 by Mahder Alemseged Gebremedhin, 4 years ago

This is what the generated code for the function looks:

DLLExport
modelica_real omc_TestFunctionRecordArray_f__eval1(threadData_t *threadData, modelica_real _v)
{
  modelica_real _rout_v;
  real_array _rout_x;
  _tailrecursive: OMC_LABEL_UNUSED
  // _rout_v has no default value.
  // _rout_x has no default value.
  _rout_v = _v;

  _rout._x = _OMC_LIT0;
  _return: OMC_LABEL_UNUSED
  return _rout_v;
}

A few things to notice here. First the function name is different. It seems there was an attempt to evaluate the function as you can see from the new name it has got f__eval1 instead of just f. This is done by the backed here.

The output of the function is also changed from a record to just a real variable. Probably by the same code in the backend. I am not sure why this is done.

The body, however, seems to have been half-way fixed to match the changes. The assignment to the variable rout.v of the record is fixed to a simple variable rout_v to reflect that there is no record anymore. However the array assignment of rout.x has not been changed. My guess is that a missing case or similar matching failure.

Per is the last person who has modified the relevant part of the code. So hopefully he can find it easier. If not I will take a look later next week.


Version 0, edited 4 years ago by Mahder Alemseged Gebremedhin (next)

in reply to:  1 comment:2 by Per Östlund, 4 years ago

Replying to mahge930:

Per is the last person who has modified the relevant part of the code. So hopefully he can find it easier.

Not really, I just made some changes to DAE.FUNCTION a while ago that just happened to touch that code. No one seems to have made any significant changes to EvaluateFunctions in the last 5-6 years.

comment:3 by Mahder Alemseged Gebremedhin, 4 years ago

Status: newaccepted

comment:4 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.