Opened 9 years ago

Closed 9 years ago

Last modified 4 years ago

#3395 closed defect (fixed)

problem codegen and records

Reported by: jan.hagemann@… Owned by: Martin Sjölund
Priority: high Milestone: 1.9.3
Component: Code Generation Version: trunk
Keywords: Cc:

Description

The code generation does not work for the following example:

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:

/*
 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
}

Change History (8)

comment:1 by Martin Sjölund, 9 years ago

Owner: changed from Lennart Ochel to Martin Sjölund
Status: newaccepted

comment:2 by Martin Sjölund, 9 years ago

Milestone: Future1.9.3
Resolution: fixed
Status: acceptedclosed

Fixed in 49ec8ae/OMCompiler.

comment:3 by Martin Sjölund, 9 years ago

comment:4 by anonymous, 4 years ago

Hi,

I have a similar problem to what is described in this ticket.
I am not sure what it means that it is "fixed in 49ec8ae/OMCompiler".

How do I apply this fix?

Best regards,

comment:5 by Philip Hannebohm, 4 years ago

You apply the fix by using the newest version of openmodelica (or a version beyond 1.9.3).
Since this is five years ago, I guess you have a more recent version and your problem isn't fixed by that fix.

Can you provide a small model that reproduces the problem? If it turns out to be unrelated to the above issue, please open a new ticket.

in reply to:  5 ; comment:6 by anonymous, 4 years ago

Replying to phannebohm:

You apply the fix by using the newest version of openmodelica (or a version beyond 1.9.3).
Since this is five years ago, I guess you have a more recent version and your problem isn't fixed by that fix.

Can you provide a small model that reproduces the problem? If it turns out to be unrelated to the above issue, please open a new ticket.

Hi,

Thank you for your reply.
I am completely new to openmodelica, and not very familiar with c++ either.
I have tried uninstalling and reinstalling openmodelica, but now I can't even get is to build the application.

I will return after a fresh install (Any recommendations? - Im using the guide provided on https://openmodelica.org/download/download-mac)

in reply to:  6 comment:7 by anonymous, 4 years ago

Replying to anonymous:

Replying to phannebohm:

You apply the fix by using the newest version of openmodelica (or a version beyond 1.9.3).
Since this is five years ago, I guess you have a more recent version and your problem isn't fixed by that fix.

Can you provide a small model that reproduces the problem? If it turns out to be unrelated to the above issue, please open a new ticket.

Hi,

Thank you for your reply.
I am completely new to openmodelica, and not very familiar with c++ either.
I have tried uninstalling and reinstalling openmodelica, but now I can't even get is to build the application.

I will return after a fresh install (Any recommendations? - Im using the guide provided on https://openmodelica.org/download/download-mac)

Hi again, phannebohm.

I have been struggling with my installation for a couple of days now, both on linux and OSx because i couldn't run the solution file my professor provided me.

However it turns out that it must be some error in the solution my professor provided, since I now realise I can run other files.

in reply to:  6 comment:8 by Philip Hannebohm, 4 years ago

Replying to anonymous:

I am completely new to openmodelica, and not very familiar with c++ either.

A great resource for getting to know Modelica is the online book Modelica by Example by Michael Tiller.
Luckily, as a user, you shouldn't need to know all about C or C++, if we do our job right.

If after that chat with your professor there remain issues with the model or your installation, you can always open a new ticket. We're happy to help :)

Note: See TracTickets for help on using tickets.