diff --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h --- a/llvm/include/llvm/IR/IntrinsicInst.h +++ b/llvm/include/llvm/IR/IntrinsicInst.h @@ -251,8 +251,16 @@ } bool hasArgList() const { return isa(getRawLocation()); } bool isKillLocation(const DIExpression *Expression) const { - return (getNumVariableLocationOps() == 0 && !Expression->isComplex()) || - any_of(location_ops(), [](Value *V) { return isa(V); }); + // Check for "kill" sentinel values. + // Non-variadic: empty metadata. + if (!hasArgList() && isa(getRawLocation())) + return true; + // Variadic: empty DIArgList with empty expression. + if (getNumVariableLocationOps() == 0 && !Expression->isComplex()) + return true; + // Variadic and non-variadic: Interpret expressions using undef or poison + // values as kills. + return any_of(location_ops(), [](Value *V) { return isa(V); }); } friend bool operator==(const RawLocationWrapper &A, diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp --- a/llvm/unittests/IR/DebugInfoTest.cpp +++ b/llvm/unittests/IR/DebugInfoTest.cpp @@ -190,6 +190,47 @@ EXPECT_TRUE(isa(DVIs[0]->getValue(0))); } +TEST(DbgVariableIntrinsic, EmptyMDIsKillLocation) { + LLVMContext Ctx; + std::unique_ptr M = parseIR(Ctx, R"( + define dso_local void @fun() local_unnamed_addr #0 !dbg !9 { + entry: + call void @llvm.dbg.declare(metadata !{}, metadata !13, metadata !DIExpression()), !dbg !16 + ret void, !dbg !16 + } + + declare void @llvm.dbg.declare(metadata, metadata, metadata) + + !llvm.dbg.cu = !{!0} + !llvm.module.flags = !{!2, !3} + !llvm.ident = !{!8} + + !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 16.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None) + !1 = !DIFile(filename: "test.c", directory: "/") + !2 = !{i32 7, !"Dwarf Version", i32 5} + !3 = !{i32 2, !"Debug Info Version", i32 3} + !8 = !{!"clang version 16.0.0"} + !9 = distinct !DISubprogram(name: "fun", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12) + !10 = !DISubroutineType(types: !11) + !11 = !{null} + !12 = !{!13} + !13 = !DILocalVariable(name: "a", scope: !9, file: !1, line: 1, type: !14) + !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) + !16 = !DILocation(line: 1, column: 21, scope: !9) + )"); + + bool BrokenDebugInfo = true; + verifyModule(*M, &errs(), &BrokenDebugInfo); + ASSERT_FALSE(BrokenDebugInfo); + + // Get the dbg.declare. + Function &F = *cast(M->getNamedValue("fun")); + DbgVariableIntrinsic *DbgDeclare = + cast(&F.front().front()); + // Check that this form counts as a "no location" marker. + EXPECT_TRUE(DbgDeclare->isKillLocation()); +} + TEST(DIBuiler, CreateFile) { LLVMContext Ctx; std::unique_ptr M(new Module("MyModule", Ctx));