Index: lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp @@ -426,14 +426,27 @@ // Print the MMO with more information from the SelectionDAG. static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO, const SelectionDAG *G) { - const MachineFunction &MF = G->getMachineFunction(); - const Function &F = MF.getFunction(); - const MachineFrameInfo &MFI = MF.getFrameInfo(); - const TargetInstrInfo *TII = G->getSubtarget().getInstrInfo(); - ModuleSlotTracker MST(F.getParent()); - MST.incorporateFunction(F); + const Module *M = nullptr; + const MachineFunction *MF = nullptr; + const MachineFrameInfo *MFI = nullptr; + const TargetInstrInfo *TII = nullptr; + LLVMContext *Ctx = nullptr; + std::unique_ptr CtxPtr; + if (G) { + MF = &G->getMachineFunction(); + M = MF->getFunction().getParent(); + MFI = &MF->getFrameInfo(); + TII = G->getSubtarget().getInstrInfo(); + Ctx = G->getContext(); + } else { + CtxPtr = llvm::make_unique(); + Ctx = CtxPtr.get(); + } + ModuleSlotTracker MST(M); + if (MF) + MST.incorporateFunction(MF->getFunction()); SmallVector SSNs; - MMO.print(OS, MST, SSNs, *G->getContext(), &MFI, TII); + MMO.print(OS, MST, SSNs, *Ctx, MFI, TII); } #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)