[clang] da65fe1 - Revert "[clang][AArch64] Avoid a crash when a non-reserved register is used (#117419)"
Igor Kudrin via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 6 15:10:57 PST 2024
Author: Igor Kudrin
Date: 2024-12-06T15:10:40-08:00
New Revision: da65fe1c16308cdb71b2fd26aaedc0ce52521ab4
URL: https://github.com/llvm/llvm-project/commit/da65fe1c16308cdb71b2fd26aaedc0ce52521ab4
DIFF: https://github.com/llvm/llvm-project/commit/da65fe1c16308cdb71b2fd26aaedc0ce52521ab4.diff
LOG: Revert "[clang][AArch64] Avoid a crash when a non-reserved register is used (#117419)"
This reverts commit 8fc6fca9f28ce20d76066be66fcc41aa38f7dc3d.
Added:
clang/test/Driver/aarch64-fixed-register-global.c
Modified:
clang/lib/Basic/Targets/AArch64.cpp
clang/test/Sema/aarch64-fixed-global-register.c
Removed:
clang/test/CodeGen/AArch64/fixed-register-global.c
################################################################################
diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index 53e102bbe44687..b7d374c67f33ef 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -232,23 +232,14 @@ bool AArch64TargetInfo::validateTarget(DiagnosticsEngine &Diags) const {
bool AArch64TargetInfo::validateGlobalRegisterVariable(
StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const {
- if (RegName == "sp") {
+ if ((RegName == "sp") || RegName.starts_with("x")) {
HasSizeMismatch = RegSize != 64;
return true;
- }
- if (RegName.starts_with("w"))
+ } else if (RegName.starts_with("w")) {
HasSizeMismatch = RegSize != 32;
- else if (RegName.starts_with("x"))
- HasSizeMismatch = RegSize != 64;
- else
- return false;
- StringRef RegNum = RegName.drop_front();
- // Check if the register is reserved. See also
- // AArch64TargetLowering::getRegisterByName().
- return RegNum == "0" ||
- (RegNum == "18" &&
- llvm::AArch64::isX18ReservedByDefault(getTriple())) ||
- getTargetOpts().FeatureMap.lookup(("reserve-x" + RegNum).str());
+ return true;
+ }
+ return false;
}
bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef,
diff --git a/clang/test/CodeGen/AArch64/fixed-register-global.c b/clang/test/CodeGen/AArch64/fixed-register-global.c
deleted file mode 100644
index afaddc1f3f1128..00000000000000
--- a/clang/test/CodeGen/AArch64/fixed-register-global.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/// Check that -ffixed register handled for globals.
-/// Regression test for #76426, #109778
-
-// RUN: %clang -c --target=aarch64-none-gnu -ffixed-x15 %s 2>&1 | count 0
-
-// RUN: not %clang -c --target=aarch64-none-gnu %s 2>&1 | \
-// RUN: FileCheck %s --check-prefix=ERR_INVREG
-// ERR_INVREG: error: register 'x15' unsuitable for global register variables on this target
-
-// RUN: not %clang -c --target=aarch64-none-gnu -ffixed-x15 -DTYPE=short %s 2>&1 | \
-// RUN: FileCheck %s --check-prefix=ERR_SIZE
-// ERR_SIZE: error: size of register 'x15' does not match variable size
-
-#ifndef TYPE
-#define TYPE long
-#endif
-
-register TYPE x15 __asm__("x15");
-
-TYPE foo() {
- return x15;
-}
diff --git a/clang/test/Driver/aarch64-fixed-register-global.c b/clang/test/Driver/aarch64-fixed-register-global.c
new file mode 100644
index 00000000000000..7b1fb118fcdf71
--- /dev/null
+++ b/clang/test/Driver/aarch64-fixed-register-global.c
@@ -0,0 +1,12 @@
+// Check that -ffixed register handled for globals.
+// Regression test for #76426
+// RUN: %clang --target=aarch64-none-gnu -ffixed-x15 -### %s 2>&1 | FileCheck %s
+// CHECK-NOT: fatal error: error in backend: Invalid register name "x15".
+register int i1 __asm__("x15");
+
+int foo() {
+ return i1;
+}
+int main() {
+ return foo();
+}
diff --git a/clang/test/Sema/aarch64-fixed-global-register.c b/clang/test/Sema/aarch64-fixed-global-register.c
index f66c3475dae38f..9b4a422d8c1b2c 100644
--- a/clang/test/Sema/aarch64-fixed-global-register.c
+++ b/clang/test/Sema/aarch64-fixed-global-register.c
@@ -1,13 +1,4 @@
-// RUN: %clang_cc1 -triple aarch64-unknown-none-gnu %s -target-feature +reserve-x4 -target-feature +reserve-x15 -verify -verify=no_x18 -fsyntax-only
-// RUN: %clang_cc1 -triple aarch64-unknown-android %s -target-feature +reserve-x4 -target-feature +reserve-x15 -verify -fsyntax-only
+// RUN: %clang_cc1 -triple aarch64-unknown-none-gnu %s -verify -fsyntax-only
-register int w0 __asm__ ("w0");
-register long x0 __asm__ ("x0");
register char i1 __asm__ ("x15"); // expected-error {{size of register 'x15' does not match variable size}}
-register long long l2 __asm__ ("w15"); // expected-error {{size of register 'w15' does not match variable size}}
-register int w3 __asm__ ("w3"); // expected-error {{register 'w3' unsuitable for global register variables on this target}}
-register long x3 __asm__ ("x3"); // expected-error {{register 'x3' unsuitable for global register variables on this target}}
-register int w4 __asm__ ("w4");
-register long x4 __asm__ ("x4");
-register int w18 __asm__ ("w18"); // no_x18-error {{register 'w18' unsuitable for global register variables on this target}}
-register long x18 __asm__ ("x18"); // no_x18-error {{register 'x18' unsuitable for global register variables on this target}}
+register long long l2 __asm__ ("w14"); // expected-error {{size of register 'w14' does not match variable size}}
More information about the cfe-commits
mailing list