[clang] [clang][AArch64] Avoid a crash when a non-reserved register is used (PR #117419)
Igor Kudrin via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 5 20:42:13 PST 2024
================
@@ -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());
----------------
igorkudrin wrote:
Thanks! Since this patch is focused on fixing the crash, it doesn't seem appropriate to make `AArch64TargetLowering::getRegisterByName()` more restrictive here. However, I added checks for `w??` registers in `AArch64TargetInfo::validateGlobalRegisterVariable()` and corresponding tests.
https://github.com/llvm/llvm-project/pull/117419
More information about the cfe-commits
mailing list