Index: lib/IR/AsmWriter.cpp =================================================================== --- lib/IR/AsmWriter.cpp +++ lib/IR/AsmWriter.cpp @@ -3148,13 +3148,13 @@ if (MDs.empty()) return; - if (MDNames.empty()) + if (TheModule && MDNames.empty()) TheModule->getMDKindNames(MDNames); for (const auto &I : MDs) { unsigned Kind = I.first; Out << Separator; - if (Kind < MDNames.size()) { + if (TheModule && Kind < MDNames.size()) { Out << "!"; printMetadataIdentifier(MDNames[Kind], Out); } else Index: test/Transforms/InstCombine/crash-with-debug.ll =================================================================== --- /dev/null +++ test/Transforms/InstCombine/crash-with-debug.ll @@ -0,0 +1,78 @@ +; RUN: opt < %s -instcombine -debug -S +; ModuleID = 'stack-dce.bc' + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: nounwind uwtable +define i32 @_Z6ifthenii(i32 %x, i32 %y) #0 !dbg !4 { +entry: + %retval = alloca i32, align 4 + %x.addr = alloca i32, align 4 + %y.addr = alloca i32, align 4 + store i32 %x, i32* %x.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !11, metadata !12), !dbg !13 + store i32 %y, i32* %y.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %y.addr, metadata !14, metadata !12), !dbg !15 + %0 = load i32, i32* %x.addr, align 4, !dbg !16 + %and = and i32 %0, 1, !dbg !18 + %tobool = icmp ne i32 %and, 0, !dbg !16 + br i1 %tobool, label %if.then, label %if.end, !dbg !19 + +if.then: ; preds = %entry + %1 = load i32, i32* %x.addr, align 4, !dbg !20 + %neg = xor i32 %1, -1, !dbg !22 + %add = add nsw i32 %neg, 9, !dbg !23 + store i32 %add, i32* %retval, align 4, !dbg !24 + br label %return, !dbg !24 + +if.end: ; preds = %entry + %2 = load i32, i32* %x.addr, align 4, !dbg !25 + %add1 = add nsw i32 %2, 2, !dbg !26 + store i32 %add1, i32* %retval, align 4, !dbg !27 + br label %return, !dbg !27 + +return: ; preds = %if.end, %if.then + %3 = load i32, i32* %retval, align 4, !dbg !28 + ret i32 %3, !dbg !28 +} + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!8, !9} +!llvm.ident = !{!10} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (http://llvm.org/git/clang.git 449c5870aca4e5f2a35b20ac859fca3b8d3699de) (http://llvm.org/git/llvm.git 24a3d0e0ad16e91eac0511689f0166c4123f83ee)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3) +!1 = !DIFile(filename: "stack-dce.cc", directory: "/usr/local/google/home/thanm/stack-layout") +!2 = !{} +!3 = !{!4} +!4 = distinct !DISubprogram(name: "ifthen", linkageName: "_Z6ifthenii", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, variables: !2) +!5 = !DISubroutineType(types: !6) +!6 = !{!7, !7, !7} +!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!8 = !{i32 2, !"Dwarf Version", i32 4} +!9 = !{i32 2, !"Debug Info Version", i32 3} +!10 = !{!"clang version 3.8.0 (http://llvm.org/git/clang.git 449c5870aca4e5f2a35b20ac859fca3b8d3699de) (http://llvm.org/git/llvm.git 24a3d0e0ad16e91eac0511689f0166c4123f83ee)"} +!11 = !DILocalVariable(name: "x", arg: 1, scope: !4, file: !1, line: 2, type: !7) +!12 = !DIExpression() +!13 = !DILocation(line: 2, column: 16, scope: !4) +!14 = !DILocalVariable(name: "y", arg: 2, scope: !4, file: !1, line: 2, type: !7) +!15 = !DILocation(line: 2, column: 23, scope: !4) +!16 = !DILocation(line: 4, column: 7, scope: !17) +!17 = distinct !DILexicalBlock(scope: !4, file: !1, line: 4, column: 7) +!18 = !DILocation(line: 4, column: 9, scope: !17) +!19 = !DILocation(line: 4, column: 7, scope: !4) +!20 = !DILocation(line: 5, column: 13, scope: !21) +!21 = distinct !DILexicalBlock(scope: !17, file: !1, line: 4, column: 14) +!22 = !DILocation(line: 5, column: 12, scope: !21) +!23 = !DILocation(line: 5, column: 14, scope: !21) +!24 = !DILocation(line: 5, column: 5, scope: !21) +!25 = !DILocation(line: 7, column: 10, scope: !4) +!26 = !DILocation(line: 7, column: 11, scope: !4) +!27 = !DILocation(line: 7, column: 3, scope: !4) +!28 = !DILocation(line: 9, column: 1, scope: !4)