Skip to content

Commit b3397ba

Browse files
authored
[CodeGen][LLVM] Fix MachineOperand::print crash when TII is nullptr. (llvm#135170)
This crash will caused if run this testcase: llvm/test/CodeGen/AMDGPU/llvm.amdgcn.ds.gws.barrier-fastregalloc.ll When build the SDNode, precisely build the SDNode for this ir: ```ir call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 0) ``` If want call the dump function of the new SDNode in the gdb environment like this: ```gdb p N->dump() ``` The llvm will crash. All of these is because calling ```dump()``` will cause the calling```MachineMemOperand::print()``` with the argument value for the```TII``` is nullptr. And the llvm/lib/CodeGen/MachineOperand.cpp#L1235 is a derefrence of TII. Signed-off-by: fanfuqiang <fuqiang.fan@mthreads.com>
1 parent c3eb6b7 commit b3397ba

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

llvm/lib/CodeGen/MachineOperand.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1232,13 +1232,17 @@ void MachineMemOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
12321232
OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol());
12331233
break;
12341234
default: {
1235-
const MIRFormatter *Formatter = TII->getMIRFormatter();
12361235
// FIXME: This is not necessarily the correct MIR serialization format for
12371236
// a custom pseudo source value, but at least it allows
12381237
// MIR printing to work on a target with custom pseudo source
12391238
// values.
12401239
OS << "custom \"";
1241-
Formatter->printCustomPseudoSourceValue(OS, MST, *PVal);
1240+
if (TII) {
1241+
const MIRFormatter *Formatter = TII->getMIRFormatter();
1242+
Formatter->printCustomPseudoSourceValue(OS, MST, *PVal);
1243+
} else {
1244+
PVal->printCustom(OS);
1245+
}
12421246
OS << '\"';
12431247
break;
12441248
}

0 commit comments

Comments
 (0)