Index: lib/Target/X86/X86RetpolineThunks.cpp =================================================================== --- lib/Target/X86/X86RetpolineThunks.cpp +++ lib/Target/X86/X86RetpolineThunks.cpp @@ -215,6 +215,15 @@ IRBuilder<> Builder(Entry); Builder.CreateRetVoid(); + + // MachineFunctions/MachineBasicBlocks aren't created automatically for the + // IR-level constructs we already made. Create them and insert them into the + // module. + MachineFunction &MF = MMI->getOrCreateMachineFunction(*F); + MachineBasicBlock *EntryMBB = MF.CreateMachineBasicBlock(Entry); + + // Insert EntryMBB into MF. It's not in the module until we do this. + MF.insert(MF.begin(), EntryMBB); } void X86RetpolineThunks::insertRegReturnAddrClobber(MachineBasicBlock &MBB,