https://github.com/DanielKristofKiss updated https://github.com/llvm/llvm-project/pull/94271
>From a8dabc508583ffb12982549d1bfb86cf6845c957 Mon Sep 17 00:00:00 2001 From: Daniel Kiss <daniel.k...@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.cpp | 12 ++++++++++++ clang/lib/Basic/Targets/AArch64.h | 3 +++ clang/test/Driver/aarch64-fixed-register-global.c | 12 ++++++++++++ clang/test/Sema/aarch64-fixed-global-register.c | 4 ++++ 4 files changed, 31 insertions(+) create mode 100644 clang/test/Driver/aarch64-fixed-register-global.c create mode 100644 clang/test/Sema/aarch64-fixed-global-register.c diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 5db1ce78c657f..2e6f78bf4de18 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -221,6 +221,18 @@ bool AArch64TargetInfo::validateTarget(DiagnosticsEngine &Diags) const { return true; } +bool AArch64TargetInfo::validateGlobalRegisterVariable( + StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const { + if ((RegName == "sp") || RegName.starts_with("x")) { + HasSizeMismatch = RegSize != 64; + return true; + } else if (RegName.starts_with("w")) { + HasSizeMismatch = RegSize != 32; + return true; + } + return false; +} + bool AArch64TargetInfo::validateBranchProtection(StringRef Spec, StringRef, BranchProtectionInfo &BPI, StringRef &Err) const { diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h index 12fb50286f751..22d7c420d5510 100644 --- a/clang/lib/Basic/Targets/AArch64.h +++ b/clang/lib/Basic/Targets/AArch64.h @@ -202,6 +202,9 @@ 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; }; 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..7b1fb118fcdf7 --- /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 new file mode 100644 index 0000000000000..9b4a422d8c1b2 --- /dev/null +++ b/clang/test/Sema/aarch64-fixed-global-register.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -triple aarch64-unknown-none-gnu %s -verify -fsyntax-only + +register char i1 __asm__ ("x15"); // expected-error {{size of register 'x15' does not match variable size}} +register long long l2 __asm__ ("w14"); // expected-error {{size of register 'w14' does not match variable size}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits