Skip to content

Conversation

@joker-eph
Copy link
Collaborator

During the review of #150855 we switched from 0 to 1 for the default log level used, but this macro wasn't updated.

During the review of llvm#150855 we switched from 0 to 1 for the default
log level used, but this macro wasn't updated.
@llvmbot
Copy link
Member

llvmbot commented Aug 20, 2025

@llvm/pr-subscribers-llvm-support

Author: Mehdi Amini (joker-eph)

Changes

During the review of #150855 we switched from 0 to 1 for the default log level used, but this macro wasn't updated.


Full diff: https://github.com/llvm/llvm-project/pull/154525.diff

2 Files Affected:

  • (modified) llvm/include/llvm/Support/Debug.h (+1-1)
  • (modified) llvm/unittests/Support/DebugTest.cpp (+42)
diff --git a/llvm/include/llvm/Support/Debug.h b/llvm/include/llvm/Support/Debug.h
index 55420891fe7d5..24468adef20be 100644
--- a/llvm/include/llvm/Support/Debug.h
+++ b/llvm/include/llvm/Support/Debug.h
@@ -71,7 +71,7 @@ void setCurrentDebugTypes(const char **Types, unsigned Count);
 /// is not specified, or is specified as "bitset".
 #define DEBUG_WITH_TYPE(TYPE, ...)                                             \
   do {                                                                         \
-    if (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)) {               \
+    if (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE, 1)) {            \
       __VA_ARGS__;                                                             \
     }                                                                          \
   } while (false)
diff --git a/llvm/unittests/Support/DebugTest.cpp b/llvm/unittests/Support/DebugTest.cpp
index e8b754892a4c2..ed8bfc63f0648 100644
--- a/llvm/unittests/Support/DebugTest.cpp
+++ b/llvm/unittests/Support/DebugTest.cpp
@@ -50,4 +50,46 @@ TEST(DebugTest, CommaInDebugBlock) {
   });
   EXPECT_EQ("ZYX", os1.str());
 }
+
+TEST(DebugTest, DebugWithType) {
+  llvm::DebugFlag = true;
+
+  // Check if the DEBUG_WITH_TYPE macro is enabled for the given type.
+  auto CheckDebugWithType = [](const char *Type) {
+    bool Visited = false;
+    DEBUG_WITH_TYPE(Type, { Visited = true; });
+    return Visited;
+  };
+
+  {
+    static const char *DT[] = {"A", "B"};
+    setCurrentDebugTypes(DT, sizeof(DT) / sizeof(DT[0]));
+    EXPECT_TRUE(CheckDebugWithType("A"));
+    EXPECT_TRUE(CheckDebugWithType("B"));
+    EXPECT_FALSE(CheckDebugWithType("C"));
+  }
+  {
+    static const char *DT[] = {"A:"};
+    setCurrentDebugTypes(DT, sizeof(DT) / sizeof(DT[0]));
+    EXPECT_FALSE(CheckDebugWithType("A"));
+    EXPECT_TRUE(CheckDebugWithType("B"));
+    EXPECT_TRUE(CheckDebugWithType("C"));
+  }
+  {
+    static const char *DT[] = {"A:", "B"};
+    setCurrentDebugTypes(DT, sizeof(DT) / sizeof(DT[0]));
+    EXPECT_FALSE(CheckDebugWithType("A"));
+    EXPECT_TRUE(CheckDebugWithType("B"));
+    EXPECT_FALSE(CheckDebugWithType("C"));
+  }
+  {
+    static const char *DT[] = {"A:3", "B:", "C"};
+    setCurrentDebugTypes(DT, sizeof(DT) / sizeof(DT[0]));
+    EXPECT_TRUE(CheckDebugWithType("A"));
+    EXPECT_FALSE(isCurrentDebugType("A", 4));
+    EXPECT_FALSE(CheckDebugWithType("B"));
+    EXPECT_TRUE(isCurrentDebugType("C", 10));
+    EXPECT_FALSE(CheckDebugWithType("D"));
+  }
+}
 #endif

@joker-eph joker-eph enabled auto-merge (squash) August 20, 2025 12:53
@joker-eph joker-eph merged commit 8b2028c into llvm:main Aug 20, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants