[llvm] a15b629 - Revert "Strip the full path from __FILE__ in the LDBG macro and keep only the filename (#150677)"
Jon Roelofs via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 5 18:48:26 PDT 2025
Author: Jon Roelofs
Date: 2025-08-05T18:47:46-07:00
New Revision: a15b629527a975ec592c95d69d04ef3537915d1d
URL: https://github.com/llvm/llvm-project/commit/a15b629527a975ec592c95d69d04ef3537915d1d
DIFF: https://github.com/llvm/llvm-project/commit/a15b629527a975ec592c95d69d04ef3537915d1d.diff
LOG: Revert "Strip the full path from __FILE__ in the LDBG macro and keep only the filename (#150677)"
This reverts commit 5d26e3c227f4b4a1761a8b0001b3165198def479.
It breaks the modules build of clang, since every source file has a different
version of this macro, which causes
https://green.lab.llvm.org/job/clang-stage2-Rthinlto/ to run out of space. We
should probably be using __FILE_NAME__ instead when the host compiler supports
it, but until then let's revert-to-green, and un-block the bots.
see: https://github.com/llvm/llvm-project/pull/150677
see: https://github.com/llvm/llvm-project/pull/150677#issuecomment-3156779021
rdar://157465825
Added:
Modified:
llvm/cmake/modules/LLVMProcessSources.cmake
llvm/include/llvm/Support/DebugLog.h
Removed:
################################################################################
diff --git a/llvm/cmake/modules/LLVMProcessSources.cmake b/llvm/cmake/modules/LLVMProcessSources.cmake
index cf358a88f5fb6..0670d60bf2afd 100644
--- a/llvm/cmake/modules/LLVMProcessSources.cmake
+++ b/llvm/cmake/modules/LLVMProcessSources.cmake
@@ -58,21 +58,6 @@ function(llvm_process_sources OUT_VAR)
set(sources ${ARG_UNPARSED_ARGUMENTS})
llvm_check_source_file_list(${sources})
- # Don't generate __SHORT_FILE__ on VS builds as it can prevent build parallelisation.
- if(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
- foreach(fn ${sources})
- get_filename_component(suf ${fn} EXT)
- if("${suf}" STREQUAL ".cpp" OR "${suf}" STREQUAL ".c")
- get_filename_component(short_name ${fn} NAME)
- set_property(
- SOURCE ${fn}
- APPEND
- PROPERTY COMPILE_DEFINITIONS __SHORT_FILE__="${short_name}")
- endif()
- endforeach()
- endif()
-
-
# This adds .td and .h files to the Visual Studio solution:
add_td_sources(sources)
find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}")
diff --git a/llvm/include/llvm/Support/DebugLog.h b/llvm/include/llvm/Support/DebugLog.h
index a3312950da94e..386cb7f1f9716 100644
--- a/llvm/include/llvm/Support/DebugLog.h
+++ b/llvm/include/llvm/Support/DebugLog.h
@@ -41,81 +41,32 @@ namespace llvm {
//
#define LDBG(...) _GET_LDBG_MACRO(__VA_ARGS__)(__VA_ARGS__)
-// Helper macros to choose the correct macro based on the number of arguments.
-#define LDBG_FUNC_CHOOSER(_f1, _f2, ...) _f2
-#define LDBG_FUNC_RECOMPOSER(argsWithParentheses) \
- LDBG_FUNC_CHOOSER argsWithParentheses
-#define LDBG_CHOOSE_FROM_ARG_COUNT(...) \
- LDBG_FUNC_RECOMPOSER((__VA_ARGS__, LDBG_LOG_LEVEL, ))
-#define LDBG_NO_ARG_EXPANDER() , LDBG_LOG_LEVEL_1
-#define _GET_LDBG_MACRO(...) \
- LDBG_CHOOSE_FROM_ARG_COUNT(LDBG_NO_ARG_EXPANDER __VA_ARGS__())
-
-// Dispatch macros to support the `level` argument or none (default to 1)
-#define LDBG_LOG_LEVEL(LEVEL) \
- DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), LEVEL, DEBUG_TYPE)
-#define LDBG_LOG_LEVEL_1() LDBG_LOG_LEVEL(1)
-
-#define DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(STREAM, LEVEL, TYPE, FILE, \
- LINE) \
- for (bool _c = \
- (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE, LEVEL)); \
- _c; _c = false) \
- for (::llvm::impl::RAIINewLineStream NewLineStream{(STREAM)}; _c; \
- _c = false) \
- ::llvm::impl::raw_ldbg_ostream{ \
- ::llvm::impl::computePrefix(TYPE, FILE, LINE, LEVEL), NewLineStream} \
- .asLvalue()
-
-#define DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, FILE) \
- DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(STREAM, LEVEL, TYPE, FILE, __LINE__)
-// When __SHORT_FILE__ is not defined, the File is the full path,
-// otherwise __SHORT_FILE__ is defined in CMake to provide the file name
-// without the path prefix.
-#if defined(__SHORT_FILE__)
-#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, LEVEL, TYPE) \
- DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, __SHORT_FILE__)
-#else
-#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, LEVEL, TYPE) \
- DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, \
- ::llvm::impl::getShortFileName(__FILE__))
-#endif
+#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \
+ for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \
+ _c = false) \
+ ::llvm::impl::LogWithNewline(TYPE, __FILE__, __LINE__, (STREAM))
namespace impl {
-
-/// A raw_ostream that tracks `\n` and print the prefix after each
-/// newline.
-class LLVM_ABI raw_ldbg_ostream final : public raw_ostream {
- std::string Prefix;
- raw_ostream &Os;
- bool HasPendingNewline;
-
- /// Split the line on newlines and insert the prefix before each
- /// newline. Forward everything to the underlying stream.
- void write_impl(const char *Ptr, size_t Size) final {
- auto Str = StringRef(Ptr, Size);
- // Handle the initial prefix.
- if (!Str.empty())
- writeWithPrefix(StringRef());
-
- auto Eol = Str.find('\n');
- while (Eol != StringRef::npos) {
- StringRef Line = Str.take_front(Eol + 1);
- if (!Line.empty())
- writeWithPrefix(Line);
- HasPendingNewline = true;
- Str = Str.drop_front(Eol + 1);
- Eol = Str.find('\n');
- }
- if (!Str.empty())
- writeWithPrefix(Str);
+class LogWithNewline {
+public:
+ LogWithNewline(const char *debug_type, const char *file, int line,
+ raw_ostream &os)
+ : os(os) {
+ if (debug_type)
+ os << "[" << debug_type << "] ";
+ os << file << ":" << line << " ";
}
- void emitPrefix() { Os.write(Prefix.c_str(), Prefix.size()); }
- void writeWithPrefix(StringRef Str) {
- flushEol();
- Os.write(Str.data(), Str.size());
+ ~LogWithNewline() { os << '\n'; }
+ template <typename T> raw_ostream &operator<<(const T &t) && {
+ return os << t;
}
+ // Prevent copying, as this class manages newline responsibility and is
+ // intended for use as a temporary.
+ LogWithNewline(const LogWithNewline &) = delete;
+ LogWithNewline &operator=(const LogWithNewline &) = delete;
+ LogWithNewline &operator=(LogWithNewline &&) = delete;
+
public:
explicit raw_ldbg_ostream(std::string Prefix, raw_ostream &Os,
bool HasPendingNewline = true)
More information about the llvm-commits
mailing list