Index: lib/IR/AsmWriter.cpp =================================================================== --- lib/IR/AsmWriter.cpp +++ lib/IR/AsmWriter.cpp @@ -1060,12 +1060,13 @@ void SlotTracker::processInstructionMetadata(const Instruction &I) { // Process metadata used directly by intrinsics. if (const CallInst *CI = dyn_cast(&I)) - if (Function *F = CI->getCalledFunction()) - if (F->isIntrinsic()) - for (auto &Op : I.operands()) - if (auto *V = dyn_cast_or_null(Op)) - if (MDNode *N = dyn_cast(V->getMetadata())) - CreateMetadataSlot(N); + if (CI->getCalledValue()) + if (Function *F = CI->getCalledFunction()) + if (F->isIntrinsic()) + for (auto &Op : I.operands()) + if (auto *V = dyn_cast_or_null(Op)) + if (MDNode *N = dyn_cast(V->getMetadata())) + CreateMetadataSlot(N); // Process metadata attached to this instruction. SmallVector, 4> MDs; Index: test/Transforms/BDCE/dump-crash.ll =================================================================== --- /dev/null +++ test/Transforms/BDCE/dump-crash.ll @@ -0,0 +1,48 @@ +; RUN: opt -S -bdce -debug < %s 2>&1 | FileCheck %s + +; Reproducer for PR38924. +; +; Verify that it is possible to print the dbg.value when salvaging debug +; information for the or instruction. + +; CHECK: SALVAGE: call void @llvm.dbg.value(metadata i32 123, metadata ![[VAR:[0-9]+]], metadata !DIExpression(DW_OP_constu, 456, DW_OP_or, DW_OP_stack_value)), !dbg ![[LOC:[0-9]+]] +; +; CHECK: call void @llvm.dbg.value(metadata i32 123, metadata ![[VAR]], metadata !DIExpression(DW_OP_constu, 456, DW_OP_or, DW_OP_stack_value)), !dbg ![[LOC]] +; +; CHECK-DAG: ![[VAR]] = !DILocalVariable(name: "local" +; CHECK-DAG: ![[LOC]] = !DILocation(line: 234, column: 116 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: noinline norecurse nounwind readnone +declare fastcc i16 @foo() unnamed_addr #0 + +; Function Attrs: noinline norecurse noreturn nounwind readonly +define internal fastcc void @bar() unnamed_addr #1 !dbg !4 { +entry: + %call = tail call fastcc i16 @foo() + %or = or i32 123, 456 + call void @llvm.dbg.value(metadata i32 %or, metadata !7, metadata !DIExpression()), !dbg !6 + ret void +} + +; Function Attrs: nounwind readnone speculatable +declare void @llvm.dbg.value(metadata, metadata, metadata) #2 + +attributes #0 = { noinline norecurse nounwind readnone } +attributes #1 = { noinline norecurse noreturn nounwind readonly } +attributes #2 = { nounwind readnone } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 8.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !2) +!1 = !DIFile(filename: "foo.c", directory: "/") +!2 = !{} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 176, type: !5, isLocal: true, isDefinition: true, scopeLine: 177, flags: DIFlagPrototyped, isOptimized: false, unit: !0) +!5 = !DISubroutineType(types: !2) +!6 = !DILocation(line: 234, column: 116, scope: !4) +!7 = !DILocalVariable(name: "local", scope: !4, file: !1, line: 221, type: !8) +!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)