[clang] [AArch64] Add validation for Global Register Variable. (PR #94271)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 3 11:51:00 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver

Author: Daniel Kiss (DanielKristofKiss)

<details>
<summary>Changes</summary>

Fixes: #<!-- -->76426

---
Full diff: https://github.com/llvm/llvm-project/pull/94271.diff


2 Files Affected:

- (modified) clang/lib/Basic/Targets/AArch64.h (+12) 
- (added) clang/test/Driver/aarch64-fixed-register-global.c (+13) 


``````````diff
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();
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/94271


More information about the cfe-commits mailing list