Skip to content

Commit 91d16a0

Browse files
committed
Remove __SHORT_FILE__ macro definition in CMake
This per-file macro definition on the command line breaks caching of modules. See discussion in #150677 Instead we use a constexpr variable to force the constexpr evaluation by the frontend, and also the __FILE_NAME__ macro when available (clang/gcc) to spare compile-time in the frontend.
1 parent 25bf86f commit 91d16a0

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

llvm/cmake/modules/LLVMProcessSources.cmake

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,6 @@ function(llvm_process_sources OUT_VAR)
5858
set(sources ${ARG_UNPARSED_ARGUMENTS})
5959
llvm_check_source_file_list(${sources})
6060

61-
# Don't generate __SHORT_FILE__ on VS builds as it can prevent build parallelisation.
62-
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
63-
foreach(fn ${sources})
64-
get_filename_component(suf ${fn} EXT)
65-
if("${suf}" STREQUAL ".cpp" OR "${suf}" STREQUAL ".c")
66-
get_filename_component(short_name ${fn} NAME)
67-
set_property(
68-
SOURCE ${fn}
69-
APPEND
70-
PROPERTY COMPILE_DEFINITIONS __SHORT_FILE__="${short_name}")
71-
endif()
72-
endforeach()
73-
endif()
74-
75-
7661
# This adds .td and .h files to the Visual Studio solution:
7762
add_td_sources(sources)
7863
find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}")

llvm/include/llvm/Support/DebugLog.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,30 @@ namespace llvm {
5656
DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), LEVEL, DEBUG_TYPE)
5757
#define LDBG_LOG_LEVEL_1() LDBG_LOG_LEVEL(1)
5858

59+
// We want the filename without the full path. We are using the __FILE__ macro
60+
// and a constexpr function to strip the path prefix. We can avoid the frontend
61+
// repeated evaluation of __FILE__ by using the __FILE_NAME__ when defined
62+
// (gcc and clang do) which contains the file name already.
63+
#if !defined(__FILE_NAME__)
64+
#define __FILE_NAME__ ::llvm::impl::getShortFileName(__FILE__)
65+
#endif
66+
5967
#define DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(STREAM, LEVEL, TYPE, FILE, \
6068
LINE) \
6169
for (bool _c = \
6270
(::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE, LEVEL)); \
6371
_c; _c = false) \
64-
for (::llvm::impl::RAIINewLineStream NewLineStream{(STREAM)}; _c; \
65-
_c = false) \
72+
for (constexpr auto file = __FILE_NAME__; _c; _c = false) \
73+
for (::llvm::impl::RAIINewLineStream NewLineStream{(STREAM)}; _c; \
74+
_c = false) \
6675
::llvm::impl::raw_ldbg_ostream{ \
6776
::llvm::impl::computePrefix(TYPE, FILE, LINE, LEVEL), NewLineStream} \
6877
.asLvalue()
6978

7079
#define DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, FILE) \
7180
DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(STREAM, LEVEL, TYPE, FILE, __LINE__)
72-
// When __SHORT_FILE__ is not defined, the File is the full path,
73-
// otherwise __SHORT_FILE__ is defined in CMake to provide the file name
74-
// without the path prefix.
75-
#if defined(__SHORT_FILE__)
7681
#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, LEVEL, TYPE) \
77-
DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, __SHORT_FILE__)
78-
#else
79-
#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, LEVEL, TYPE) \
80-
DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, \
81-
::llvm::impl::getShortFileName(__FILE__))
82-
#endif
82+
DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, __FILE__)
8383

8484
namespace impl {
8585

llvm/unittests/Support/DebugLogTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
// This macro is defined in the LLVM build system, but we undefine it here
10-
// so that we test at least once in-tree the case where __SHORT_FILE__ is not
10+
// so that we test at least once in-tree the case where __FILE_NAME__ is not
1111
// defined.
12-
#undef __SHORT_FILE__
12+
#undef __FILE_NAME__
1313

1414
#include "llvm/Support/DebugLog.h"
1515
#include "llvm/ADT/Sequence.h"

0 commit comments

Comments
 (0)