Skip to content

Conversation

@fanfuqiang
Copy link
Member

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:

  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:

  p N->dump()

The llvm will crash.

All of these is because calling dump() will cause the callingMachineMemOperand::print()
with the argument value for theTII is nullptr.
And the llvm/lib/CodeGen/MachineOperand.cpp#L1235 is a derefrence of TII.

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 <[email protected]>
@llvmbot
Copy link
Member

llvmbot commented Apr 10, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: z (fanfuqiang)

Changes

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:

  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:

  p N-&gt;dump()

The llvm will crash.

All of these is because calling dump() will cause the callingMachineMemOperand::print()
with the argument value for theTII is nullptr.
And the llvm/lib/CodeGen/MachineOperand.cpp#L1235 is a derefrence of TII.


Full diff: https://github.com/llvm/llvm-project/pull/135170.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/MachineOperand.cpp (+6-2)
diff --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp
index 231d66607b700..0d251697f2567 100644
--- a/llvm/lib/CodeGen/MachineOperand.cpp
+++ b/llvm/lib/CodeGen/MachineOperand.cpp
@@ -1232,13 +1232,17 @@ void MachineMemOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
           OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol());
       break;
     default: {
-      const MIRFormatter *Formatter = TII->getMIRFormatter();
       // FIXME: This is not necessarily the correct MIR serialization format for
       // a custom pseudo source value, but at least it allows
       // MIR printing to work on a target with custom pseudo source
       // values.
       OS << "custom \"";
-      Formatter->printCustomPseudoSourceValue(OS, MST, *PVal);
+      if (TII) {
+        const MIRFormatter *Formatter = TII->getMIRFormatter();
+        Formatter->printCustomPseudoSourceValue(OS, MST, *PVal);
+      } else {
+        PVal->printCustom(OS);
+      }
       OS << '\"';
       break;
     }

@fanfuqiang
Copy link
Member Author

fanfuqiang commented Apr 10, 2025

Run the testcase: llvm/test/CodeGen/AMDGPU/llvm.amdgcn.ds.gws.barrier-fastregalloc.ll
The callstack catch the crash:

image

@fanfuqiang fanfuqiang merged commit b3397ba into llvm:main Apr 11, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants