-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Global -Ctarget-feature flags not applied to entry function #146143
Copy link
Copy link
Closed
Labels
A-target-featureArea: Enabling/disabling target features like AVX, Neon, etc.Area: Enabling/disabling target features like AVX, Neon, etc.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-target-featureArea: Enabling/disabling target features like AVX, Neon, etc.Area: Enabling/disabling target features like AVX, Neon, etc.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I encountered an issue where global
-Ctarget-featureflags are not consistently applied to the program’s entry function (e.g. main).When passing
-Ctarget-feature=-avx, the compiler does not attach the expected function-leveltarget-featuresattributes to the entry function. As a result, the AVX feature is not fully disabled in that context. This leads to inconsistencies between global target feature settings and the actual function attributes emitted byrustc.This discrepancy becomes particularly problematic under LTO. In cases where a feature is explicitly disabled in the Rust frontend but implicitly enabled by the LLVM backend for the target architecture, the entry function ends up with mismatched assumptions, potentially causing miscompilation or unexpected behavior.
I tried this code:
I expected to see this happen:
The global target features should be applied to the entry function.
Instead, this happened:
The global target features were not applied to the entry function.
Meta
rustc --version --verbose: