Skip to content

Commit e1aa2df

Browse files
authored
[flang-rt] Use -Wp to undefine macros (#156034)
If the macro was previously defined with `-Wp,-D` then a later `-U` is *not* going to take effect, the `-Wp` flag takes precedence. Instead use `-Wp,-U`. This works regardless of whether the original definition was provided via `-D` or `-Wp,-D`. Also make sure these flags only get passed to the C++ compiler -- they are only relevant there, and flang does not support `-Wp`.
1 parent 23302a2 commit e1aa2df

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

flang-rt/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,11 @@ if (UNIX AND CMAKE_SYSTEM_NAME MATCHES "AIX")
255255
add_compile_definitions(_LARGE_FILE_API)
256256
endif ()
257257

258-
# Check whether the compiler can undefine a macro using the "-U" flag.
258+
# Check whether the compiler can undefine a macro using the "-Wp,-U" flag.
259259
# Aternatively, we could use
260260
# CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU"
261261
# but some older versions of CMake don't define it for GCC itself.
262-
check_cxx_compiler_flag("-UTESTFLAG" FLANG_RT_SUPPORTS_UNDEFINE_FLAG)
262+
check_cxx_compiler_flag("-Wp,-UTESTFLAG" FLANG_RT_SUPPORTS_UNDEFINE_FLAG)
263263

264264
# Check whether -fno-lto is supported.
265265
check_cxx_compiler_flag(-fno-lto FLANG_RT_HAS_FNO_LTO_FLAG)

flang-rt/cmake/modules/AddFlangRT.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,10 @@ function (add_flangrt_library name)
283283
# build, to avoid an unwanted dependency on libstdc++/libc++.so.
284284
target_compile_definitions(${tgtname} PUBLIC _GLIBCXX_NO_ASSERTIONS)
285285
if (FLANG_RT_SUPPORTS_UNDEFINE_FLAG)
286-
target_compile_options(${tgtname} PUBLIC -U_GLIBCXX_ASSERTIONS)
287-
target_compile_options(${tgtname} PUBLIC -U_LIBCPP_ENABLE_ASSERTIONS)
286+
target_compile_options(${tgtname} PUBLIC
287+
"$<$<COMPILE_LANGUAGE:CXX>:-Wp,-U_GLIBCXX_ASSERTIONS>")
288+
target_compile_options(${tgtname} PUBLIC
289+
"$<$<COMPILE_LANGUAGE:CXX>:-Wp,-U_LIBCPP_ENABLE_ASSERTIONS>")
288290
endif ()
289291

290292
# Non-GTest unittests depend on LLVMSupport

0 commit comments

Comments
 (0)