diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1980,8 +1980,12 @@ Asm->OutStreamer->AddComment("Loc expr size"); if (getDwarfVersion() >= 5) Asm->EmitULEB128(DebugLocs.getBytes(Entry).size()); - else + else if (DebugLocs.getBytes(Entry).size() <= std::numeric_limits::max()) Asm->emitInt16(DebugLocs.getBytes(Entry).size()); + else + // The entry is too big to fit into 16 bit, drop it as there is nothing we + // can do. + return; // Emit the entry. APByteStreamer Streamer(*Asm); emitDebugLocEntry(Streamer, Entry);