[llvm] clang crash assigning to a global named register variable #109778 (PR #113105)
David Spickett via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 4 05:28:22 PST 2024
================
@@ -11522,8 +11522,10 @@ getRegisterByName(const char* RegName, LLT VT, const MachineFunction &MF) const
if (AArch64::X1 <= Reg && Reg <= AArch64::X28) {
const AArch64RegisterInfo *MRI = Subtarget->getRegisterInfo();
unsigned DwarfRegNum = MRI->getDwarfRegNum(Reg, false);
- if (!Subtarget->isXRegisterReserved(DwarfRegNum) &&
- !MRI->isReservedReg(MF, Reg))
----------------
DavidSpickett wrote:
I think you are on the wrong track here, though it took me a while to figure out why.
If you look at the RISC-V backend its version of this function is much more clear. Basically this one and the RISC-V one are saying:
Lookup a register by name (the name that came from the declaration)
If that register is one that can be used at all by user code (is not the stack pointer or other crucial ABI registers)
Then see if anyone has reserved it globally or in this function
If no one has reserved it, then we cannot put the global named register variable there because it will get overwritten
Adding the `-ffixed-x<N>` option (https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-ffixed-x1) reserves the register so one of those `!isreserved` is now true and the register index is returned, which avoids the crash.
So the problem here is not the logic, it's that the reporting of the problem is vague (each backend phrases the message differently) and its a clang crash not a nice error telling the user what to do.
https://github.com/llvm/llvm-project/pull/113105
More information about the llvm-commits
mailing list