Skip to content

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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ReVe1uv
Copy link
Contributor

@ReVe1uv ReVe1uv commented May 8, 2025

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_property() and removes the flag from the global EXTRA_FLAGS.

[4875/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingInternal.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4876/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfiling.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4877/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingBuffer.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4878/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/GCDAProfiling.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4879/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingValue.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4881/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingNameVar.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4882/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingMergeFile.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4883/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingVersionVar.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4884/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingMerge.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4885/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingPlatformAIX.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4886/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingPlatformFuchsia.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4887/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingPlatformDarwin.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4888/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingPlatformOther.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4890/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingPlatformWindows.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4892/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingPlatformLinux.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4893/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingWriter.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4894/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingFile.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4895/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingUtil.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C

@llvmbot llvmbot added compiler-rt PGO Profile Guided Optimizations labels May 8, 2025
@llvmbot
Copy link
Member

llvmbot commented May 8, 2025

@llvm/pr-subscribers-pgo

Author: Wang Qiang (ReVe1uv)

Changes

Avoid passing the C++-specific -nostdinc++ flag to C source files in the profile runtime library, which triggers warnings when building with Clang:

  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.

[4875/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingInternal.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4876/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfiling.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4877/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingBuffer.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4878/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/GCDAProfiling.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4879/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingValue.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4881/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingNameVar.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4882/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingMergeFile.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4883/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingVersionVar.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4884/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingMerge.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4885/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingPlatformAIX.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4886/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingPlatformFuchsia.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4887/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingPlatformDarwin.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4888/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingPlatformOther.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4890/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingPlatformWindows.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4892/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingPlatformLinux.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4893/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingWriter.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4894/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingFile.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C
[4895/15653] Building C object projects/compiler-rt/lib/profile/CMakeFiles/clang_rt.profile-x86_64.dir/InstrProfilingUtil.c.o
cc1: warning: command-line option ‘-nostdinc++’ is valid for C++/ObjC++ but not for C

Full diff: https://github.com/llvm/llvm-project/pull/139038.diff

1 Files Affected:

  • (modified) compiler-rt/lib/profile/CMakeLists.txt (+7-1)
diff --git a/compiler-rt/lib/profile/CMakeLists.txt b/compiler-rt/lib/profile/CMakeLists.txt
index ac1451c8ceed1..2a6a79a41cb97 100644
--- a/compiler-rt/lib/profile/CMakeLists.txt
+++ b/compiler-rt/lib/profile/CMakeLists.txt
@@ -142,7 +142,13 @@ 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_source_files_properties(
+    InstrProfilingRuntime.cpp
+    PROPERTIES
+      COMPILE_FLAGS "-nostdinc++"
+  )
+endif()
 # XRay uses C++ standard library headers.
 string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
 

@ReVe1uv ReVe1uv force-pushed the compiler-rt-warning-fix branch 2 times, most recently from efe9453 to 83a1734 Compare May 8, 2025 07:58
…ntime

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`.
@ReVe1uv ReVe1uv force-pushed the compiler-rt-warning-fix branch from 83a1734 to 5a90df8 Compare May 9, 2025 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants