@@ -732,6 +732,67 @@ TEST(Local, FindDbgUsers) {
732
732
EXPECT_EQ (Vals.size (), 1u );
733
733
}
734
734
735
+ TEST (Local, FindDbgRecords) {
736
+ // DbgRecord copy of the FindDbgUsers test above.
737
+ LLVMContext Ctx;
738
+ std::unique_ptr<Module> M = parseIR (Ctx,
739
+ R"(
740
+ define dso_local void @fun(ptr %a) #0 !dbg !11 {
741
+ entry:
742
+ call void @llvm.dbg.assign(metadata ptr %a, metadata !16, metadata !DIExpression(), metadata !15, metadata ptr %a, metadata !DIExpression()), !dbg !19
743
+ ret void
744
+ }
745
+
746
+ !llvm.dbg.cu = !{!0}
747
+ !llvm.module.flags = !{!2, !3, !9}
748
+ !llvm.ident = !{!10}
749
+
750
+ !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
751
+ !1 = !DIFile(filename: "test.cpp", directory: "/")
752
+ !2 = !{i32 7, !"Dwarf Version", i32 5}
753
+ !3 = !{i32 2, !"Debug Info Version", i32 3}
754
+ !4 = !{i32 1, !"wchar_size", i32 4}
755
+ !9 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
756
+ !10 = !{!"clang version 17.0.0"}
757
+ !11 = distinct !DISubprogram(name: "fun", linkageName: "fun", scope: !1, file: !1, line: 1, type: !12, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14)
758
+ !12 = !DISubroutineType(types: !13)
759
+ !13 = !{null}
760
+ !14 = !{}
761
+ !15 = distinct !DIAssignID()
762
+ !16 = !DILocalVariable(name: "x", scope: !11, file: !1, line: 2, type: !17)
763
+ !17 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64)
764
+ !18 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
765
+ !19 = !DILocation(line: 0, scope: !11)
766
+ )" );
767
+
768
+ bool BrokenDebugInfo = true ;
769
+ verifyModule (*M, &errs (), &BrokenDebugInfo);
770
+ ASSERT_FALSE (BrokenDebugInfo);
771
+ bool NewDbgInfoFormat = UseNewDbgInfoFormat;
772
+ UseNewDbgInfoFormat = true ;
773
+ M->convertToNewDbgValues ();
774
+
775
+ Function &Fun = *cast<Function>(M->getNamedValue (" fun" ));
776
+ Value *Arg = Fun.getArg (0 );
777
+
778
+ SmallVector<DbgVariableIntrinsic *> Users;
779
+ SmallVector<DbgVariableRecord *> Records;
780
+ // Arg (%a) is used twice by a single dbg_assign. Check findDbgUsers returns
781
+ // only 1 pointer to it rather than 2.
782
+ findDbgUsers (Users, Arg, &Records);
783
+ EXPECT_EQ (Users.size (), 0u );
784
+ EXPECT_EQ (Records.size (), 1u );
785
+
786
+ SmallVector<DbgValueInst *> Vals;
787
+ Records.clear ();
788
+ // Arg (%a) is used twice by a single dbg_assign. Check findDbgValues returns
789
+ // only 1 pointer to it rather than 2.
790
+ findDbgValues (Vals, Arg, &Records);
791
+ EXPECT_EQ (Vals.size (), 0u );
792
+ EXPECT_EQ (Records.size (), 1u );
793
+ UseNewDbgInfoFormat = NewDbgInfoFormat;
794
+ }
795
+
735
796
TEST (Local, ReplaceAllDbgUsesWith) {
736
797
using namespace llvm ::dwarf;
737
798
0 commit comments