@@ -50,4 +50,46 @@ TEST(DebugTest, CommaInDebugBlock) {
5050 });
5151 EXPECT_EQ (" ZYX" , os1.str ());
5252}
53+
54+ TEST (DebugTest, DebugWithType) {
55+ llvm::DebugFlag = true ;
56+
57+ // Check if the DEBUG_WITH_TYPE macro is enabled for the given type.
58+ auto CheckDebugWithType = [](const char *Type) {
59+ bool Visited = false ;
60+ DEBUG_WITH_TYPE (Type, { Visited = true ; });
61+ return Visited;
62+ };
63+
64+ {
65+ static const char *DT[] = {" A" , " B" };
66+ setCurrentDebugTypes (DT, sizeof (DT) / sizeof (DT[0 ]));
67+ EXPECT_TRUE (CheckDebugWithType (" A" ));
68+ EXPECT_TRUE (CheckDebugWithType (" B" ));
69+ EXPECT_FALSE (CheckDebugWithType (" C" ));
70+ }
71+ {
72+ static const char *DT[] = {" A:" };
73+ setCurrentDebugTypes (DT, sizeof (DT) / sizeof (DT[0 ]));
74+ EXPECT_FALSE (CheckDebugWithType (" A" ));
75+ EXPECT_TRUE (CheckDebugWithType (" B" ));
76+ EXPECT_TRUE (CheckDebugWithType (" C" ));
77+ }
78+ {
79+ static const char *DT[] = {" A:" , " B" };
80+ setCurrentDebugTypes (DT, sizeof (DT) / sizeof (DT[0 ]));
81+ EXPECT_FALSE (CheckDebugWithType (" A" ));
82+ EXPECT_TRUE (CheckDebugWithType (" B" ));
83+ EXPECT_FALSE (CheckDebugWithType (" C" ));
84+ }
85+ {
86+ static const char *DT[] = {" A:3" , " B:" , " C" };
87+ setCurrentDebugTypes (DT, sizeof (DT) / sizeof (DT[0 ]));
88+ EXPECT_TRUE (CheckDebugWithType (" A" ));
89+ EXPECT_FALSE (isCurrentDebugType (" A" , 4 ));
90+ EXPECT_FALSE (CheckDebugWithType (" B" ));
91+ EXPECT_TRUE (isCurrentDebugType (" C" , 10 ));
92+ EXPECT_FALSE (CheckDebugWithType (" D" ));
93+ }
94+ }
5395#endif
0 commit comments