Skip to content

Remove __SHORT_FILE__ macro definition in CMake #152344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions llvm/cmake/modules/LLVMProcessSources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
21 changes: 11 additions & 10 deletions llvm/include/llvm/Support/DebugLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ namespace llvm {
DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), LEVEL, DEBUG_TYPE)
#define LDBG_LOG_LEVEL_1() LDBG_LOG_LEVEL(1)

// We want the filename without the full path. We are using the __FILE__ macro
// and a constexpr function to strip the path prefix. We can avoid the frontend
// repeated evaluation of __FILE__ by using the __FILE_NAME__ when defined
// (gcc and clang do) which contains the file name already.
#if defined(__FILE_NAME__)
#define __LLVM_FILE_NAME__ __FILE_NAME__
#else
#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 = \
Expand All @@ -69,17 +79,8 @@ namespace llvm {

#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
DEBUGLOG_WITH_STREAM_TYPE_AND_FILE(STREAM, LEVEL, TYPE, __LLVM_FILE_NAME__)

namespace impl {

Expand Down
5 changes: 0 additions & 5 deletions llvm/unittests/Support/DebugLogTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
//
//===----------------------------------------------------------------------===//

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

#include "llvm/Support/DebugLog.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/Support/raw_ostream.h"
Expand Down