-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang][AArch64] Avoid a crash when a non-reserved register is used #117419
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -232,13 +232,23 @@ bool AArch64TargetInfo::validateTarget(DiagnosticsEngine &Diags) const { | |
|
|
||
| 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")) { | ||
| if (RegName.starts_with("w")) { | ||
| HasSizeMismatch = RegSize != 32; | ||
| return true; | ||
| } | ||
| if (RegName == "sp") { | ||
| HasSizeMismatch = RegSize != 64; | ||
| return true; | ||
| } | ||
| if (RegName.starts_with("x")) { | ||
| HasSizeMismatch = RegSize != 64; | ||
| // Check if the register is reserved. See also | ||
| // AArch64TargetLowering::getRegisterByName(). | ||
| return RegName == "x0" || | ||
| (RegName == "x18" && | ||
| llvm::AArch64::isX18ReservedByDefault(getTriple())) || | ||
| getTargetOpts().FeatureMap.lookup(("reserve-" + RegName).str()); | ||
|
||
| } | ||
| return false; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /// Check that -ffixed register handled for globals. | ||
| /// Regression test for #76426, #109778 | ||
|
|
||
| // RUN: %clang -c --target=aarch64-none-gnu -ffixed-x15 %s 2>&1 | count 0 | ||
|
|
||
| // RUN: not %clang -c --target=aarch64-none-gnu %s 2>&1 | \ | ||
| // RUN: FileCheck %s --check-prefix=ERR_INVREG | ||
| // ERR_INVREG: error: register 'x15' unsuitable for global register variables on this target | ||
|
|
||
| // RUN: not %clang -c --target=aarch64-none-gnu -ffixed-x15 -DTYPE=short %s 2>&1 | \ | ||
| // RUN: FileCheck %s --check-prefix=ERR_SIZE | ||
| // ERR_SIZE: error: size of register 'x15' does not match variable size | ||
|
|
||
| #ifndef TYPE | ||
| #define TYPE long | ||
| #endif | ||
|
|
||
| register TYPE x15 __asm__("x15"); | ||
|
|
||
| TYPE foo() { | ||
| return x15; | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,9 @@ | ||
| // RUN: %clang_cc1 -triple aarch64-unknown-none-gnu %s -verify -fsyntax-only | ||
| // RUN: %clang_cc1 -triple aarch64-unknown-none-gnu %s -target-feature +reserve-x4 -target-feature +reserve-x15 -verify -verify=no_x18 -fsyntax-only | ||
| // RUN: %clang_cc1 -triple aarch64-unknown-android %s -target-feature +reserve-x4 -target-feature +reserve-x15 -verify -fsyntax-only | ||
|
|
||
| register long x0 __asm__ ("x0"); | ||
| 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}} | ||
| register long x3 __asm__ ("x3"); // expected-error {{register 'x3' unsuitable for global register variables on this target}} | ||
| register long x4 __asm__ ("x4"); | ||
| register long x18 __asm__ ("x18"); // no_x18-error {{register 'x18' unsuitable for global register variables on this target}} |
Uh oh!
There was an error while loading. Please reload this page.