Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Improve code generation for ADD/SUB_ARRAY_SCALAR.
Browse files Browse the repository at this point in the history
- Store the source array in a temporary variable, to avoid taking the
  address of a an rvalue.

Belonging to [master]:
  - #2830
  • Loading branch information
perost authored and OpenModelica-Hudson committed Dec 13, 2018
1 parent 7b01c95 commit 23e4c45
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Compiler/Template/CodegenCFunctions.tpl
Expand Up @@ -5082,12 +5082,24 @@ case BINARY(__) then
let type = match ty case T_ARRAY(ty=T_INTEGER(__)) then "integer_array"
case T_ARRAY(ty=T_ENUMERATION(__)) then "integer_array"
else "real_array"
'add_alloc_scalar_<%type%>(<% if isArrayType(typeof(exp1)) then '<%e2%>, &<%e1%>' else '<%e1%>, &<%e2%>' %>)'
let tvar = tempDecl(type, &varDecls)
if isArrayType(typeof(exp1)) then
let &preExp += '<%tvar%> = <%e1%>;<%\n%>'
'add_alloc_scalar_<%type%>(<%e2%>, &<%tvar%>)'
else
let &preExp += '<%tvar%> = <%e2%>;<%\n%>'
'add_alloc_scalar_<%type%>(<%e1%>, &<%tvar%>)'
case SUB_SCALAR_ARRAY(__) then
let type = match ty case T_ARRAY(ty=T_INTEGER(__)) then "integer_array"
case T_ARRAY(ty=T_ENUMERATION(__)) then "integer_array"
else "real_array"
'sub_alloc_scalar_<%type%>(<% if isArrayType(typeof(exp1)) then '<%e2%>, &<%e1%>' else '<%e1%>, &<%e2%>' %>)'
let tvar = tempDecl(type, &varDecls)
if isArrayType(typeof(exp1)) then
let &preExp += '<%tvar%> = <%e1%>;<%\n%>'
'sub_alloc_scalar_<%type%>(<%e2%>, &<%tvar%>)'
else
let &preExp += '<%tvar%> = <%e2%>;<%\n%>'
'sub_alloc_scalar_<%type%>(<%e1%>, &<%tvar%>)'
case MUL_SCALAR_PRODUCT(__) then
let type = match ty case T_ARRAY(ty=T_INTEGER(__)) then "integer_scalar"
case T_ARRAY(ty=T_ENUMERATION(__)) then "integer_scalar"
Expand Down

0 comments on commit 23e4c45

Please sign in to comment.