﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3395	problem codegen and records	jan.hagemann@…	Martin Sjölund	"The code generation does not work for the following example:


{{{#!mo
model FunctionCallTest5
  record R
    Real r1;
    Integer r2;
  end R;
    
  function f4
    input Real x1;
    input Real x2;
    input R r;
    output R y1;
    output Real y2;
  algorithm
    y1.r1 := if x1>x2 then sin(r.r1) else cos(r.r2);
    y1.r2 := integer(ceil(y1.r1));
    for i in 1:y1.r2 loop
      y1.r1 := y1.r1+x1*x2+r.r1*r.r2;
    end for;
    y2 := r.r1*r.r2;
  end f4;

  R cse4, y;
  Real cse5;
equation
  y = cse4;
  (cse4, cse5) = f4(time, 0, R(time, 2));
end FunctionCallTest5;
}}}

the error message is the following:

{{{
FunctionCallTest5.c:96:3: error: assignment to cast is illegal, lvalue casts are not supported
  (modelica_integer)$Py$Pr2 = tmp0._r2;
  ^~~~~~~~~~~~~~~~~~~~~~~~~ ~
FunctionCallTest5.c:239:4: warning: incompatible pointer types initializing 'modelica_boolean (*)(DATA *, long)' with an expression of type 'modelica_boolean (DATA *)' [-Wincompatible-pointer-types]
   FunctionCallTest5_function_equationsSynchronous
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.
make: *** [FunctionCallTest5.o] Error 1
make: *** Waiting for unfinished jobs....
FunctionCallTest5_06inz.c:59:3: error: assignment to cast is illegal, lvalue casts are not supported
  (modelica_integer)$Py$Pr2 = tmp0._r2;
  ^~~~~~~~~~~~~~~~~~~~~~~~~ ~
1 error generated.
}}}


the generated c-code is the following:

{{{#!c

/*
 equation index: 2
 type: ALGORITHM
 
   (FunctionCallTest5.R(y.r1, y.r2), cse5) := FunctionCallTest5.f4(time, 0.0, FunctionCallTest5.R(time, 2));
 */
void FunctionCallTest5_eqFunction_2(DATA *data)
{
  TRACE_PUSH
  const int equationIndexes[2] = {1,2};
  FunctionCallTest5_R tmp0;
  /* tuple assignment FunctionCallTest5.R(y.r1, y.r2), cse5*/
  tmp0 = omc_FunctionCallTest5_f4(threadData, time, 0.0, omc_FunctionCallTest5_R(threadData, time, (modelica_integer) 2) ,&$Pcse5);
  $Py$Pr1 = tmp0._r1;
  (modelica_integer)$Py$Pr2 = tmp0._r2;
  TRACE_POP
}

}}}"	defect	closed	high	1.9.3	Code Generation	trunk	fixed		
