From 5a90df8e1fd084312e86148719b547b99239534f Mon Sep 17 00:00:00 2001 From: Kane Wang Date: Thu, 8 May 2025 14:12:33 +0800 Subject: [PATCH] [compiler-rt][NFC] Apply -nostdinc++ only to C++ source in profile runtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid passing the C++-specific `-nostdinc++` flag to C source files in the profile runtime library, which triggers warnings when building with GCC: cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C We only need `-nostdinc++` for `InstrProfilingRuntime.cpp` to prevent accidental inclusion of the C++ standard library headers. This patch scopes the flag to that file using `set_properties()` and removes the flag from the global `EXTRA_FLAGS`. --- compiler-rt/lib/profile/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/profile/CMakeLists.txt b/compiler-rt/lib/profile/CMakeLists.txt index ac1451c8ceed1..d859d905d9613 100644 --- a/compiler-rt/lib/profile/CMakeLists.txt +++ b/compiler-rt/lib/profile/CMakeLists.txt @@ -142,7 +142,10 @@ if(MSVC) endif() # We don't use the C++ Standard Library here, so avoid including it by mistake. -append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ EXTRA_FLAGS) +if(COMPILER_RT_HAS_NOSTDINCXX_FLAG) +set_property(SOURCE InstrProfilingRuntime.cpp APPEND_STRING + PROPERTY COMPILE_FLAGS " -nostdinc++") +endif() # XRay uses C++ standard library headers. string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")