Repository navigation
mccode-complex-lib: make the wrappers static inline - #3121
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Free-form text area
Please describe what your PR is adding in terms of features or bugfixes:
Bugfix:
mccode-complex-lib.hdefines its wrappers (cplx,cneg,radd,rmul,cadd,csub,cmul,cdiv) as plain C99inline. 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.undefined reference to 'cmul'.Test_Phonon_BvK_PGfrom Initial commit of Phonon_BvK_PG and test instrument #2344 or Phonon_BvK_PG: OpenACC port (component + eigen solver), drop NOACC #3002 at-O0:cadd/cmulare undefined. At-O2it usually links, which is why this stayed hidden.Fix:
static inlineon 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-devmicromamba env. Not tested locally: gcc, Linux, and MSVC. MSVC already acceptedinlinein C, sostatic inlineis 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
Test_lib_mccode_complex_libcovers inclusion, not this link-time caseTest output (macOS arm64, clang):
Test_Phonon_BvK_PG(Phonon_BvK_PG: OpenACC port (component + eigen solver), drop NOACC #3002): before,-O0fails to link (cmulundefined) and-O2links. After, both-O0and-O2link.-DOPENACCsyntax check of the same generated C (stub OpenACC headers): clean.Test_lib_mccode_complex_lib, McStas and McXtrace, built at-O0with the old and with the new header: all link, andNcount=10givesPSD_I=10as in the%Testline.🤖 Generated with Claude Code