Skip to content

Commit 3918596

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 3918596

File tree

3 files changed

+11
-30
lines changed

3 files changed

+11
-30
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: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ 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 __LLVM_FILE_NAME__ __FILE_NAME__
65+
#else
66+
#define __LLVM_FILE_NAME__ ::llvm::impl::getShortFileName(__FILE__)
67+
#endif
68+
5969
#define DEBUGLOG_WITH_STREAM_TYPE_FILE_AND_LINE(STREAM, LEVEL, TYPE, FILE, \
6070
LINE) \
6171
for (bool _c = \
@@ -69,17 +79,8 @@ namespace llvm {
6979

7080
#define DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, FILE) \
7181
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__)
7682
#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
83+
DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, __LLVM_FILE_NAME__)
8384

8485
namespace impl {
8586

llvm/unittests/Support/DebugLogTest.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// 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
11-
// defined.
12-
#undef __SHORT_FILE__
13-
149
#include "llvm/Support/DebugLog.h"
1510
#include "llvm/ADT/Sequence.h"
1611
#include "llvm/Support/raw_ostream.h"

0 commit comments

Comments
 (0)