[clang] [AArch64] Add validation for Global Register Variable. (PR #94271)
Daniel Kiss via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 3 11:50:31 PDT 2024
https://github.com/DanielKristofKiss created https://github.com/llvm/llvm-project/pull/94271
Fixes: #76426
>From cda747d06c2d363c6c0c7f7d72825d119240ac5a Mon Sep 17 00:00:00 2001
From: Daniel Kiss <daniel.kiss at arm.com>
Date: Sun, 21 Apr 2024 16:14:25 +0200
Subject: [PATCH] [AArch64] Add validation for Global Register Variable.
Fixes: #76426
---
clang/lib/Basic/Targets/AArch64.h | 12 ++++++++++++
clang/test/Driver/aarch64-fixed-register-global.c | 13 +++++++++++++
2 files changed, 25 insertions(+)
create mode 100644 clang/test/Driver/aarch64-fixed-register-global.c
diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h
index 12fb50286f751..9165865029900 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -202,6 +202,18 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
bool hasBitIntType() const override { return true; }
bool validateTarget(DiagnosticsEngine &Diags) const override;
+
+ bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
+ bool &HasSizeMismatch) const override {
+ if (RegName.equals("sp") || RegName.starts_with("x")) {
+ HasSizeMismatch = RegSize != 64;
+ return true;
+ } else if (RegName.starts_with("w")) {
+ HasSizeMismatch = RegSize != 32;
+ return true;
+ }
+ return false;
+ }
};
class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
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 0000000000000..6a05228277cd6
--- /dev/null
+++ b/clang/test/Driver/aarch64-fixed-register-global.c
@@ -0,0 +1,13 @@
+// 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();
+}
More information about the cfe-commits
mailing list