Skip to content

Commit

Permalink
[AArch64] Add validation for Global Register Variable.
Browse files Browse the repository at this point in the history
Fixes: llvm#76426
  • Loading branch information
DanielKristofKiss committed Jun 3, 2024
1 parent 72c901f commit cda747d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions clang/lib/Basic/Targets/AArch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions clang/test/Driver/aarch64-fixed-register-global.c
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit cda747d

Please sign in to comment.