Skip to content

mccode-complex-lib: make the wrappers static inline - #3121

Merged
willend merged 1 commit into
mainfrom
complex-lib-static-inline
Nov 16, 2026
Merged

willend merged 1 commit into
mainfrom
complex-lib-static-inline

Conversation

@willend

@willend willend commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Free-form text area

Please describe what your PR is adding in terms of features or bugfixes:

Bugfix: mccode-complex-lib.h defines its wrappers (cplx, cneg, radd, rmul, cadd, csub, cmul, cdiv) as plain C99 inline. C99 then expects an external definition in some other translation unit, and there is none. So the link fails whenever the compiler keeps a call instead of inlining it.

Fix: static inline on all 16 wrappers, in both the gcc/clang and the MSVC branches. Each translation unit gets its own copy if it needs one. The code generated with optimisation is unchanged, and numerical results don't change.

Both McStas and McXtrace pick this up through common/lib/share. The same commit (a33edef) is also on #3002, so CI there can go green. Whichever PR lands second will see it as already applied.

Unit test: Test_lib_mccode_complex_lib (McStas and McXtrace) already exists, but it only %includes the library and never calls a wrapper, so it can't catch this. Making it call the wrappers would also only catch this at -O0, since CI builds with optimisation on.


Declaration of use of AI-tools


Development OS / boundary conditions

Please describe what OS you developed and tested your additions on, and if any special dependencies are required:

macOS arm64, Apple clang, mccode-dev micromamba env. Not tested locally: gcc, Linux, and MSVC. MSVC already accepted inline in C, so static inline is expected to be fine; CI will confirm.


PR Checklist for contributing to McStas/McXtrace

  • My work touches / adds to the runtime lib code (.c,.h etc in multiple locations

    • I am have added reasoning and documentation for the change below
    • I am attaching test output in the comments
    • Unit test: see the note in the free-form text: the existing Test_lib_mccode_complex_lib covers inclusion, not this link-time case

Test output (macOS arm64, clang):

  • Generated C of Test_Phonon_BvK_PG (Phonon_BvK_PG: OpenACC port (component + eigen solver), drop NOACC #3002): before, -O0 fails to link (cmul undefined) and -O2 links. After, both -O0 and -O2 link.
  • -DOPENACC syntax check of the same generated C (stub OpenACC headers): clean.
  • Test_lib_mccode_complex_lib, McStas and McXtrace, built at -O0 with the old and with the new header: all link, and Ncount=10 gives PSD_I=10 as in the %Test line.

🤖 Generated with Claude Code

Plain C99 inline has no external definition, so the link fails with
"undefined reference to cmul" whenever the compiler does not inline a
call (e.g. at -O0, or Phonon_BvK_PG's eigen solver with clang on Ubuntu).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@willend
willend merged commit 6dc3c37 into main Nov 16, 2026
28 checks passed
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