Skip to content

BUG: Allow . and + in -march/-mtune strip regex (issue #6133, backport to release-5.4)#6157

Merged
hjmjohnson merged 1 commit intoInsightSoftwareConsortium:release-5.4from
hjmjohnson:fix-issue-6133-march-regex-rel54
Apr 28, 2026
Merged

BUG: Allow . and + in -march/-mtune strip regex (issue #6133, backport to release-5.4)#6157
hjmjohnson merged 1 commit intoInsightSoftwareConsortium:release-5.4from
hjmjohnson:fix-issue-6133-march-regex-rel54

Conversation

@hjmjohnson
Copy link
Copy Markdown
Member

@hjmjohnson hjmjohnson commented Apr 28, 2026

Backport of the main-branch fix for #6133 to release-5.4, slated for inclusion in 5.4.7. One-line regex tweak in Wrapping/macro_files/itk_auto_load_submodules.cmake.

On Arch Linux aarch64 with CXXFLAGS="-march=armv8.2-a+fp16+rcpc+dotprod+crypto", the strip regex -march=[a-zA-Z0-9\-]* matched only the armv8 prefix and left .2-a+fp16+rcpc+dotprod+crypto dangling — clang then read it as a positional file and failed:

clang++: error: no such file or directory: '.2-a+fp16+rcpc+dotprod+crypto'

Widen the class to [A-Za-z0-9._+\-]* so the entire -march=/-mtune= token is consumed.

Why a separate backport PR (rather than auto-cherry-pick)

release-5.4's copy of the file uses the older single-line CMake formatting (pre-gersemi), so the line-level diff differs from main even though the change is semantically identical. The fix on main lands separately on main against the gersemi-formatted file.

Verification

Same minimal CMake regex repro as the main-branch PR confirms the buggy class drops the dangling tail and the fixed class consumes it cleanly. No build/test changes; this is a configure-time string tweak with no API/ABI impact.

Cross-reference:

@github-actions github-actions Bot added the type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances label Apr 28, 2026
@hjmjohnson hjmjohnson marked this pull request as ready for review April 28, 2026 12:53
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 28, 2026

Greptile Summary

This is a one-line configure-time regex fix in generate_castxml_commandline_flags that widens the character class for -march=/-mtune= stripping from [a-zA-Z0-9\-]* to [A-Za-z0-9._+\-]*. The change correctly resolves the issue where extended ARM/x86 architecture strings (e.g., armv8.2-a+fp16+rcpc+dotprod+crypto) were only partially consumed, leaving a dangling token that clang misinterpreted as a file path.

Confidence Score: 5/5

Safe to merge — minimal, well-targeted configure-time fix with no API/ABI impact.

Single-line regex widening in a CMake helper; character class is syntactically correct for CMake ERE ('.' and '+' are literal inside '[]', '-' is an escaped hyphen consistent with the original code), the change is fully backward-compatible, and no logic beyond string stripping is affected.

No files require special attention.

Important Files Changed

Filename Overview
Wrapping/macro_files/itk_auto_load_submodules.cmake Widens the -march=/-mtune= strip regex character class to include '.', '+', and '_', fixing truncation of extended ARM/x86 micro-architecture strings that caused clang to misinterpret the dangling suffix as a file argument.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["CMAKE_CXX_FLAGS e.g.<br/>-march=armv8.2-a+fp16+rcpc+dotprod+crypto -O2"] --> B["REGEX REPLACE loop over<br/>INVALID_OPTIMIZATION_FLAGS"]
    B --> C1["-fopenmp → stripped"]
    B --> C2["-march=[A-Za-z0-9._+\-]* → stripped (entire token)"]
    B --> C3["-mtune=[A-Za-z0-9._+\-]* → stripped (entire token)"]
    B --> C4["-mfma → stripped"]
    C1 & C2 & C3 & C4 --> D["Cleaned _castxml_cc_flags<br/>e.g. -O2"]
    D --> E["separate_arguments → passed to castxml"]

    style C2 fill:#d4edda,stroke:#28a745
    style C3 fill:#d4edda,stroke:#28a745
Loading

Reviews (1): Last reviewed commit: "BUG: Allow '.' and '+' in -march/-mtune ..." | Re-trigger Greptile

…twareConsortium#6133)

Backport of the main-branch fix to release-5.4 for inclusion in 5.4.7.

The aggressive optimization flag stripping in
generate_castxml_commandline_flags() must remove -march=/-mtune=
arguments before feeding the compiler line to castxml, because
castxml's bundled clang preprocessor does not accept all backend
target features. The previous regex character class
[a-zA-Z0-9\-]* stopped at the first non-alphanumeric, non-hyphen
character, so extended target descriptors silently lost their tail:

  -march=armv8.2-a+fp16+rcpc+dotprod+crypto
       ^^^^^^^^^                              <-- only this much matched
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <-- this remained verbatim

The leftover fragment ".2-a+fp16+rcpc+dotprod+crypto" was then
passed to clang as a positional argument, producing:

  clang++: error: no such file or directory: '.2-a+fp16+rcpc+dotprod+crypto'

Reported on Arch Linux aarch64 against ITK 5.4.6. The same class
of breakage applies to extended x86 names like -march=znver3 or
-march=skylake-avx512.

Extend the character class to [A-Za-z0-9._+\-]* so the entire token
is matched and stripped.
@hjmjohnson hjmjohnson force-pushed the fix-issue-6133-march-regex-rel54 branch from dd09e8f to a6522f6 Compare April 28, 2026 16:11
@hjmjohnson hjmjohnson merged commit f265b15 into InsightSoftwareConsortium:release-5.4 Apr 28, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants