-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][AArch64] Add validation for Global Register Variable. #94271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-backend-aarch64 @llvm/pr-subscribers-clang Author: Daniel Kiss (DanielKristofKiss) ChangesFixes: #76426 Full diff: https://github.com/llvm/llvm-project/pull/94271.diff 2 Files Affected:
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();
+}
|
@llvm/pr-subscribers-clang-driver Author: Daniel Kiss (DanielKristofKiss) ChangesFixes: #76426 Full diff: https://github.com/llvm/llvm-project/pull/94271.diff 2 Files Affected:
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();
+}
|
@DanielKristofKiss Thanks for the fix. At first glance, LGTM. I'll take a closer look in a few days. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix. I left a minor suggestion.
Some notes:
- This commit make Clang emit
error: size of register '???' does not match variable size
error instead offatal error: error in backend: Invalid register name "???"
, regardless of the-ffixed-???
option. - [AArch64] Crash when compiling global register variable __asm__("x15") without -ffixed-x15 #76426 says "When
-ffixed-x15
is specified, it can be compiled.". When-ffixed-x15
is specified, older revisions (including 18.1.x releases) compiles the program in [AArch64] Crash when compiling global register variable __asm__("x15") without -ffixed-x15 #76426 without an error but the generated code is incorrect (thefoo
function is compiled intomrs w0, NZCV; ret
!). Recent revisions emitsfatal error: error in backend: Invalid register name "x15".
. So make it a Clang error is appropriate. - GCC allows this variable-register size mismatch. Clang does not allow.
- We don't need to use
starts_with_insensitive
. Register names are case-sensitive (same as GCC).
cda747d
to
a8dabc5
Compare
…s used (#117419) Relanding the patch with a fix for a test failure on build bots that do not build LLVM for AArch64. Fixes #76426, #109778 (for AArch64) The previous patch for this issue, #94271, generated an error message if a register and a global variable did not have the same size. This patch checks if the register is reserved.
Fixes: #76426