[compiler-rt] [compiler-rt][NFC] Apply -nostdinc++ only to C++ source in profile runtime (PR #139038)

Wang Qiang via llvm-commits llvm-commits at lists.llvm.org
Thu May 8 00:58:33 PDT 2025


https://github.com/ReVe1uv updated https://github.com/llvm/llvm-project/pull/139038

>From 83a1734ac8954cb2312cc7fb8284f0921e52003b Mon Sep 17 00:00:00 2001
From: Kane Wang <wangqiang1 at kylinos.cn>
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_source_files_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}")
 



More information about the llvm-commits mailing list