[llvm] Introduce LDBG_OS() macro as a variant of LDBG() (PR #157194)

Andrzej WarzyƄski via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 8 02:43:37 PDT 2025


================
@@ -76,29 +105,137 @@ namespace llvm {
 #define __LLVM_FILE_NAME__ ::llvm::impl::getShortFileName(__FILE__)
 #endif
 
-#define DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(STREAM, LEVEL, TYPE, FILE,     \
-                                                LINE)                          \
-  for (bool _c =                                                               \
-           (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE, LEVEL));     \
+/// These macros are detecting if the DEBUG_TYPE or LDBG_DEBUG_STREAM macros are
+/// defined. They are using a combination of preprocessor tricks and C++17
+// used-defined string literals to achieve this.
+// For example, if DEBUG_TYPE is defined to "foo", the preprocessor will expand
+// the macro and then stringify the result to
+//  "foo"_LDBG_VARIABLE_CHECK
+// This dispatch to the user-defined string literal operator named
+// _LDBG_VARIABLE_CHECK which returns true. Otherwise it expands to
+// DEBUG_TYPE_LDBG_VARIABLE_CHECK which we define as a macro that returns false.
----------------
banach-space wrote:

```suggestion
/// These macros detect if the DEBUG_TYPE or LDBG_DEBUG_STREAM macros are
/// defined. They are use a combination of preprocessor tricks and C++17
/// user-defined string literals to achieve this.
/// For example, if DEBUG_TYPE is defined to "foo", the preprocessor will expand
/// the macro and then stringify the result to
///  "foo"_LDBG_VARIABLE_CHECK
/// This dispatches to the user-defined string literal operator named
/// _LDBG_VARIABLE_CHECK which returns true. Otherwise, it expands to
/// DEBUG_TYPE_LDBG_VARIABLE_CHECK which we define as a macro that returns false.
```

1. Use Doxygen consistently.
2. Follow existing style ("are detecting" - > "detect").

Now. are user-defined string literals really C++17 trick? These date back to C++11, no? https://en.cppreference.com/w/cpp/language/user_literal.html

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


More information about the llvm-commits mailing list