[libcxx-commits] [libcxx] 36df92d - [libcxx] Only add -GR- option to MSVC or clang-cl builds

David Spickett via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 6 07:47:10 PDT 2023


Author: David Spickett
Date: 2023-07-06T14:47:02Z
New Revision: 36df92dcd9195e002f91390b3dca1a8b66dedfe2

URL: https://github.com/llvm/llvm-project/commit/36df92dcd9195e002f91390b3dca1a8b66dedfe2
DIFF: https://github.com/llvm/llvm-project/commit/36df92dcd9195e002f91390b3dca1a8b66dedfe2.diff

LOG: [libcxx] Only add -GR- option to MSVC or clang-cl builds

Previously we added both `-GR-` and `-fno-rtti` if RTTI was disabled.
When building with clang 16.x, that caused this error in part of the build:
```
clang-16: error: argument unused during compilation: '-G R-' [-Werror,-Wunused-command-line-argument]
```
I think the strange message is because clang is seeing `R-` as the argument
to `-G`, which is a valid clang option.

`-GR-` is an alternate syntax for the `/GR-` option for MSVC
(the dash means disable RTTI):
https://learn.microsoft.com/en-us/cpp/build/reference/gr-enable-run-time-type-information?view=msvc-170

This error is sort of fixed by cd18efb61d759405956dbd30e4b5f2720d8e1783
but not intentionally. Also, we'd have to wait for 17.x to benefit from that.

The proper fix here is to only add `-GR-` if we are building with MSVC
or the MSVC-like clang-cl, and add `-fno-rtti` if not.

Reviewed By: #libc, simon_tatham, michaelplatings, ldionne

Differential Revision: https://reviews.llvm.org/D154582

Added: 
    

Modified: 
    libcxx/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 3b58f81cde53a1..6d8f83ffee29d4 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -569,8 +569,11 @@ endfunction()
 # RTTI flags ==================================================================
 function(cxx_add_rtti_flags target)
   if (NOT LIBCXX_ENABLE_RTTI)
-    target_add_compile_flags_if_supported(${target} PUBLIC -GR-)
-    target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti)
+    if (LIBCXX_TARGETING_CLANG_CL OR LIBCXX_TARGETING_MSVC)
+      target_add_compile_flags_if_supported(${target} PUBLIC -GR-)
+    else()
+      target_add_compile_flags_if_supported(${target} PUBLIC -fno-rtti)
+    endif()
   endif()
 endfunction()
 


        


More information about the libcxx-commits mailing list