[clang] [clang][AArch64] Don't #define __ARM_FEATURE_CRC32 when -crc is specified in -target-feature (PR #132167)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 20 01:49:33 PDT 2025
https://github.com/XiaShark created https://github.com/llvm/llvm-project/pull/132167
Currently, clang incorrectly defines the `__ARM_FEATURE_CRC32` macro even when `-crc` is explicitly specified in `-target-feature`. This can lead to unexpected behavior in code that relies on this macro.
See the example at https://godbolt.org/z/n4xsch3qv
This commit fixed the issue by adding a secondary check to confirm if `-crc` is specified in `-target-feature`.
>From 8ad45b1c02dc762752b13eed91d9ed5bd60bbefd Mon Sep 17 00:00:00 2001
From: XiaShark <xiajingze1 at huawei.com>
Date: Thu, 20 Mar 2025 14:32:30 +0800
Subject: [PATCH] [clang][AArch64] Don't #define __ARM_FEATURE_CRC32 when -crc
is specified in -target-feature
Currently, clang incorrectly defines the `__ARM_FEATURE_CRC32` macro
even when `-crc` is explicitly specified in `-target-feature`. This can
lead to unexpected behavior in code that relies on this macro.
This commit fixed the issue by adding a secondary check to confirm if
`-crc` is specified in `-target-feature`.
---
clang/lib/Basic/Targets/AArch64.cpp | 8 +++++---
clang/test/Preprocessor/aarch64-target-features.c | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index 3633bab6e0df9..f21e7d2c4d7b4 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1192,17 +1192,19 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
}
}
+ setDataLayout();
+ setArchFeatures();
+
// Check features that are manually disabled by command line options.
// This needs to be checked after architecture-related features are handled,
// making sure they are properly disabled when required.
for (const auto &Feature : Features) {
if (Feature == "-d128")
HasD128 = false;
+ if (Feature == "-crc")
+ HasCRC = false;
}
- setDataLayout();
- setArchFeatures();
-
if (HasNoFP) {
FPU &= ~FPUMode;
FPU &= ~NeonMode;
diff --git a/clang/test/Preprocessor/aarch64-target-features.c b/clang/test/Preprocessor/aarch64-target-features.c
index b10c55447d9af..6efad0f4983d7 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -120,7 +120,9 @@
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-a+crc -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-CRC32 %s
// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.1-a -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-CRC32 %s
// RUN: %clang -target arm64-none-linux-gnu -march=armv8.1-a -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-CRC32 %s
+// RUN: %clang -target arm64-none-linux-gnu -march=armv8.1-a+nocrc -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-NOCRC %s
// CHECK-CRC32: __ARM_FEATURE_CRC32 1
+// CHECK-NOCRC-NOT: __ARM_FEATURE_CRC32 1
// RUN: %clang -target aarch64-none-linux-gnu -fno-math-errno -fno-signed-zeros\
// RUN: -fno-trapping-math -fassociative-math -freciprocal-math -fapprox-func\
More information about the cfe-commits
mailing list