Fix for Issue Loading MGXS Data Files with LLVM 20 or Newer #3368
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.
Description
Currently, OpenMC crashes with errors like:
when reading in
mgxs.h5
multigroup data files when using LLVM clang version 20 or newer. More info is in Issue #3367.The Cause
The debugger reveals the crash is coming from this xtensor operation in mgxs.cpp:
Specifically, the
xt::argmin
part of the operation. This seems like a valid operation and works fine in gcc and LLVM 19 and older, but appears to break in LLVM 20 and newer. My best guess is that this is related to the relaxed template arguments issue in xtensor. It's possible this issue is fixed in xtensor 0.26.0, but that is unfortunately also the version of xtensor where they refactored the API seemingly for no reason (which I expect might get rolled back?). So, updating the xtensor version is not a good option.The Fix
Instead of using
xt::argmin
we just find the closest element manually with a for loop. Not as elegant but gets the job done! Note there are other areas in the code that usext:argmin
but perhaps they don't break as they are being used on different types where the relaxed template issue doesn't get tripped.Fixes #3367
Checklist