Index: lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp +++ lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp @@ -147,9 +147,12 @@ } // Add the BLOCK. - MachineInstr *Begin = BuildMI(*Header, InsertPos, MBB.findDebugLoc(InsertPos), - TII.get(WebAssembly::BLOCK)) - .addImm(int64_t(WebAssembly::ExprType::Void)); + DebugLoc DL = InsertPos != Header->end() + ? Header->findDebugLoc(InsertPos) + : Header->findPrevDebugLoc(InsertPos); + MachineInstr *Begin = + BuildMI(*Header, InsertPos, DL, TII.get(WebAssembly::BLOCK)) + .addImm(int64_t(WebAssembly::ExprType::Void)); // Mark the end of the block. InsertPos = MBB.begin(); @@ -197,8 +200,10 @@ while (InsertPos != MBB.end() && InsertPos->getOpcode() == WebAssembly::END_LOOP) ++InsertPos; - MachineInstr *Begin = BuildMI(MBB, InsertPos, MBB.findDebugLoc(InsertPos), - TII.get(WebAssembly::LOOP)) + + DebugLoc DL = InsertPos != MBB.end() ? MBB.findDebugLoc(InsertPos) + : MBB.findPrevDebugLoc(InsertPos); + MachineInstr *Begin = BuildMI(MBB, InsertPos, DL, TII.get(WebAssembly::LOOP)) .addImm(int64_t(WebAssembly::ExprType::Void)); // Mark the end of the loop (using arbitrary debug location that branched