Index: lib/IR/IntrinsicInst.cpp =================================================================== --- lib/IR/IntrinsicInst.cpp +++ lib/IR/IntrinsicInst.cpp @@ -43,8 +43,10 @@ if (auto *V = dyn_cast(MD)) return V->getValue(); - // When the value goes to null, it gets replaced by an empty MDNode. - assert(!cast(MD)->getNumOperands() && "Expected an empty MDNode"); + if (!AllowNullOp) { + // When the value goes to null, it gets replaced by an empty MDNode. + assert(!cast(MD)->getNumOperands() && "Expected an empty MDNode"); + } return nullptr; } Index: test/DebugInfo/Generic/PR37395.ll =================================================================== --- /dev/null +++ test/DebugInfo/Generic/PR37395.ll @@ -0,0 +1,65 @@ +; RUN: opt -lcssa -S %s | FileCheck %s +source_filename = "small.c" + +@a = common dso_local global i32 0, align 4, !dbg !0 + +; CHECK-LABEL: @f +define dso_local void @f() !dbg !11 { +entry: + br label %for.cond, !dbg !18 + +for.cond: ; preds = %for.inc, %entry + %0 = load i32, i32* @a, align 4, !dbg !19 + %tobool = icmp ne i32 %0, 0, !dbg !20 + br i1 %tobool, label %for.body, label %for.end, !dbg !20 + +for.body: ; preds = %for.cond + br label %L, !dbg !20 + +; CHECK: L: +; CHECK: call void @llvm.dbg.label +L: ; preds = %for.body + call void @llvm.dbg.label(metadata !15), !dbg !21 + br label %for.inc, !dbg !20 + +for.inc: ; preds = %L + %1 = load i32, i32* @a, align 4, !dbg !22 + %inc = add nsw i32 %1, 1, !dbg !22 + store i32 %inc, i32* @a, align 4, !dbg !22 + br label %for.cond, !dbg !23, !llvm.loop !24 + +for.end: ; preds = %for.cond + ret void, !dbg !26 +} + +declare void @llvm.dbg.label(metadata) + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!7, !8, !9} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) +!3 = !DIFile(filename: "small.c", directory: "./") +!4 = !{} +!5 = !{!0} +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!7 = !{i32 2, !"Dwarf Version", i32 4} +!8 = !{i32 2, !"Debug Info Version", i32 3} +!9 = !{i32 1, !"wchar_size", i32 4} +!11 = distinct !DISubprogram(name: "f", scope: !3, file: !3, line: 3, type: !12, isLocal: false, isDefinition: true, scopeLine: 4, isOptimized: true, unit: !2, retainedNodes: !14) +!12 = !DISubroutineType(types: !13) +!13 = !{null} +!14 = !{!15} +!15 = !DILabel(scope: !16, name: "L", file: !3, line: 6) +!16 = distinct !DILexicalBlock(scope: !17, file: !3, line: 5, column: 3) +!17 = distinct !DILexicalBlock(scope: !11, file: !3, line: 5, column: 3) +!18 = !DILocation(line: 5, column: 3, scope: !11) +!19 = !DILocation(line: 5, column: 10, scope: !16) +!20 = !DILocation(line: 5, column: 3, scope: !17) +!21 = !DILocation(line: 6, column: 3, scope: !16) +!22 = !DILocation(line: 5, column: 14, scope: !16) +!23 = !DILocation(line: 5, column: 3, scope: !16) +!24 = distinct !{!24, !20, !25} +!25 = !DILocation(line: 6, column: 5, scope: !17) +!26 = !DILocation(line: 7, column: 1, scope: !11)