Skip to content

OCT generates non-compiling C code for Complex if-expressions in ComplexOutput equations (ComplexBlocks) - #2

Open
hubertus65 wants to merge 1 commit into
impact-failuresfrom
impact-failure-ComplexIfExpressionInConnectorEquation
Open

hubertus65 wants to merge 1 commit into
impact-failuresfrom
impact-failure-ComplexIfExpressionInConnectorEquation

Conversation

@hubertus65

Copy link
Copy Markdown
Owner

Adds ImpactFailures.ComplexIfExpressionInConnectorEquation, a minimal model with MSL 4.1.0 that fails in Modelon Impact (impact.modelon.cloud, checked 2026-10-31).

Failure: the generated C code does not compile. The record constructor of the connector
type leaks into the C source:

sources/..._equ.c: In function 'model_ode_derivatives_base':
error: 'Modelica' undeclared (first use in this function)
  _temp_..._13 = COND_EXP_EQ(_g_useConjugateInput_6, JMI_TRUE,
      (Modelica.ComplexBlocks.Interfaces.ComplexOutput(_g_u_re_7, - _g_u_im_8)).re, _g_u_re_7);

Trigger: a Complex if-expression written inline in the equation of a
ComplexOutput connector:

  • y = k*(if useConjugateInput then Modelica.ComplexMath.conj(u) else u) in ComplexMath.Gain, and likewise in Feedback, Division and Add3
  • y = offset + (if time < startTime then Complex(0) else height) in Sources.ComplexStep

Each block alone reproduces it, and so do local copies of the blocks. Assigning the if-expression to a
protected Complex variable first compiles and simulates. ComplexMath.Add and Product already
do this through u1Internal/u2Internal of Interfaces.ComplexSI2SO.

Workaround in the MSL: modelica#4847 uses intermediate variables in
the five blocks. OpenModelica results are bit-identical.

Upstream MSL pull request: modelica#4847

🤖 Generated with Claude Code

https://claude.ai/code/session_01UmNZkRw6HV9CeBvNk36AzT

OCT generates non-compiling C code for Complex if-expressions in ComplexOutput equations (ComplexBlocks)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UmNZkRw6HV9CeBvNk36AzT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant