[llvm] [flang-rt] Use -Wp to undefine macros (PR #156034)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 29 12:21:12 PDT 2025


https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/156034

>From a5277f9999d684bd42b2cef94ce008a0258cafec Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Fri, 29 Aug 2025 16:35:42 +0200
Subject: [PATCH 1/2] [flang-rt] Use -Wp to undefine macros

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`.
---
 flang-rt/cmake/modules/AddFlangRT.cmake | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake
index 66e54bd2103a3..ac7ceff6b3123 100644
--- a/flang-rt/cmake/modules/AddFlangRT.cmake
+++ b/flang-rt/cmake/modules/AddFlangRT.cmake
@@ -283,8 +283,8 @@ function (add_flangrt_library name)
     # build, to avoid an unwanted dependency on libstdc++/libc++.so.
     target_compile_definitions(${tgtname} PUBLIC _GLIBCXX_NO_ASSERTIONS)
     if (FLANG_RT_SUPPORTS_UNDEFINE_FLAG)
-      target_compile_options(${tgtname} PUBLIC -U_GLIBCXX_ASSERTIONS)
-      target_compile_options(${tgtname} PUBLIC -U_LIBCPP_ENABLE_ASSERTIONS)
+      target_compile_options(${tgtname} PUBLIC -Wp,-U_GLIBCXX_ASSERTIONS)
+      target_compile_options(${tgtname} PUBLIC -Wp,-U_LIBCPP_ENABLE_ASSERTIONS)
     endif ()
 
     # Non-GTest unittests depend on LLVMSupport

>From cb80f64e1701ee94b671bcf170159589414728c9 Mon Sep 17 00:00:00 2001
From: Nikita Popov <nikita.ppv at gmail.com>
Date: Fri, 29 Aug 2025 21:20:53 +0200
Subject: [PATCH 2/2] Limit to cxx

---
 flang-rt/cmake/modules/AddFlangRT.cmake | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake
index ac7ceff6b3123..43b1451d65e32 100644
--- a/flang-rt/cmake/modules/AddFlangRT.cmake
+++ b/flang-rt/cmake/modules/AddFlangRT.cmake
@@ -283,8 +283,10 @@ function (add_flangrt_library name)
     # build, to avoid an unwanted dependency on libstdc++/libc++.so.
     target_compile_definitions(${tgtname} PUBLIC _GLIBCXX_NO_ASSERTIONS)
     if (FLANG_RT_SUPPORTS_UNDEFINE_FLAG)
-      target_compile_options(${tgtname} PUBLIC -Wp,-U_GLIBCXX_ASSERTIONS)
-      target_compile_options(${tgtname} PUBLIC -Wp,-U_LIBCPP_ENABLE_ASSERTIONS)
+      target_compile_options(${tgtname} PUBLIC
+          "$<$<COMPILE_LANGUAGE:CXX>:-Wp,-U_GLIBCXX_ASSERTIONS>")
+      target_compile_options(${tgtname} PUBLIC
+          "$<$<COMPILE_LANGUAGE:CXX>:-Wp,-U_LIBCPP_ENABLE_ASSERTIONS>")
     endif ()
 
     # Non-GTest unittests depend on LLVMSupport



More information about the llvm-commits mailing list