Skip to content

Commit 006720b

Browse files
davemgreentru
authored andcommitted
[AArch64] Handle negative architecture features
Currently negative architecture features passes to clang like -Xclang -target-feature -Xclang -v9.3a will end up _enabling_ dependant target features (like FEAT_MOPS). This patch fixes that by ensuring we don't enable dependant target features when !Enabled. Fixes #60375 Differential Revision: https://reviews.llvm.org/D142963
1 parent c2f68bc commit 006720b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,13 @@ void AArch64TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
687687
if (ArchInfo == llvm::AArch64::INVALID)
688688
return; // Not an architecure, nothing more to do.
689689

690+
// Disabling an architecture feature does not affect dependent features
691+
if (!Enabled)
692+
return;
693+
690694
for (const auto *OtherArch : llvm::AArch64::ArchInfos)
691695
if (ArchInfo.implies(*OtherArch))
692-
Features[OtherArch->getSubArch()] = Enabled;
696+
Features[OtherArch->getSubArch()] = true;
693697

694698
// Set any features implied by the architecture
695699
uint64_t Extensions =

clang/test/CodeGen/aarch64-targetattr.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ void noneon() {}
8989
__attribute__((target("no-simd")))
9090
void nosimd() {}
9191

92+
// This isn't part of the standard interface, but test that -arch features should not apply anything else.
93+
// CHECK-LABEL: @minusarch() #18
94+
__attribute__((target("no-v9.3a")))
95+
void minusarch() {}
96+
9297
// CHECK: attributes #0 = { {{.*}} "target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" }
9398
// CHECK: attributes #1 = { {{.*}} "target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a" }
9499
// CHECK: attributes #2 = { {{.*}} "target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a" }
@@ -107,3 +112,4 @@ void nosimd() {}
107112
// CHECK: attributes #15 = { {{.*}} "target-cpu"="neoverse-n1" "target-features"="+bf16,+crc,+crypto,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a" "tune-cpu"="cortex-a710" }
108113
// CHECK: attributes #16 = { {{.*}} "branch-target-enforcement"="true" {{.*}} "target-features"="+bf16,+crc,+crypto,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a" "tune-cpu"="cortex-a710" }
109114
// CHECK: attributes #17 = { {{.*}} "target-features"="-neon" }
115+
// CHECK: attributes #18 = { {{.*}} "target-features"="-v9.3a" }

clang/test/Preprocessor/aarch64-target-features.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@
569569
// RUN: %clang -target aarch64-arm-none-eabi -march=armv9.3-a -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-MOPS %s
570570
// RUN: %clang -target aarch64-arm-none-eabi -march=armv9.3-a+nomops -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-NOMOPS %s
571571
// RUN: %clang -target aarch64-arm-none-eabi -march=armv9.3-a+mops -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-MOPS %s
572+
// Check that -target-feature -v9.3a doesn't enable dependant features
573+
// RUN: %clang -target aarch64-arm-none-eabi -Xclang -target-feature -Xclang -v9.3a -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-NOMOPS %s
572574
// CHECK-MOPS: __ARM_FEATURE_MOPS 1
573575
// CHECK-NOMOPS-NOT: __ARM_FEATURE_MOPS 1
574576

0 commit comments

Comments
 (0)