[llvm] [llvm][support] Add LLVM_DLOG macro. (PR #143704)

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 8 08:22:35 PDT 2025


================
@@ -0,0 +1,39 @@
+//===- llvm/unittest/Support/DebugLogTest.cpp -----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/DebugLog.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include <string>
+using namespace llvm;
+using testing::HasSubstr;
+
+#ifndef NDEBUG
+TEST(DebugLogTest, Basic) {
+  std::string s1, s2;
+  raw_string_ostream os1(s1), os2(s2);
+  static const char *DT[] = {"A", "B"};
+
+  llvm::DebugFlag = true;
+  setCurrentDebugTypes(DT, 2);
+  DEBUGLOG_WITH_STREAM_AND_TYPE(os1, "A") << "A";
+  DEBUGLOG_WITH_STREAM_AND_TYPE(os1, "B") << "B";
+  EXPECT_THAT(os1.str(), AllOf(HasSubstr("A\n"), HasSubstr("B\n")));
+
+  setCurrentDebugType("A");
+  volatile int x = 0;
+  if (x == 0)
----------------
joker-eph wrote:

That deserves some comment, I don't quite get the volatile x here and the check that seems always true, you're trying to force the compiler to keep dead code but I'm not sure why?

https://github.com/llvm/llvm-project/pull/143704


More information about the llvm-commits mailing list