Skip to content

Commit a7aade1

Browse files
committed
[runtimes] Synchronize warnings flags between libc++/libc++abi/libunwind
This mostly keeps the same warning flags. The most important exceptions are `-Wpedantic` and `-Wconversion`, which are now removed from libc++abi and libunwind. Reviewed By: ldionne, #libunwind, #libc, #libc_abi Spies: mikhail.ramalho, phosek, libcxx-commits Differential Revision: https://reviews.llvm.org/D144252
1 parent 88eb4cb commit a7aade1

File tree

7 files changed

+99
-136
lines changed

7 files changed

+99
-136
lines changed

libcxx/CMakeLists.txt

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
2424
set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build")
2525

2626
include(GNUInstallDirs)
27+
include(WarningFlags)
2728

2829
# Require out of source build.
2930
include(MacroEnsureOutOfSourceBuild)
@@ -563,71 +564,6 @@ function(cxx_add_basic_build_flags target)
563564
target_compile_options(${target} PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}")
564565
endfunction()
565566

566-
# Warning flags ===============================================================
567-
function(cxx_add_warning_flags target)
568-
target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
569-
if (MSVC)
570-
# -W4 is the cl.exe/clang-cl equivalent of -Wall. (In cl.exe and clang-cl,
571-
# -Wall is equivalent to -Weverything in GCC style compiler drivers.)
572-
target_add_compile_flags_if_supported(${target} PRIVATE -W4)
573-
else()
574-
target_add_compile_flags_if_supported(${target} PRIVATE -Wall)
575-
endif()
576-
target_add_compile_flags_if_supported(${target} PRIVATE -Wextra
577-
-W
578-
-Wwrite-strings
579-
-Wno-unused-parameter
580-
-Wno-long-long
581-
-Werror=return-type
582-
-Wextra-semi
583-
-Wundef
584-
-Wunused-template
585-
-Wformat-nonliteral)
586-
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
587-
target_add_compile_flags_if_supported(${target} PRIVATE
588-
-Wno-user-defined-literals
589-
-Wno-covered-switch-default
590-
-Wno-suggest-override
591-
)
592-
if (LIBCXX_TARGETING_CLANG_CL)
593-
target_add_compile_flags_if_supported(${target} PRIVATE
594-
-Wno-c++98-compat
595-
-Wno-c++98-compat-pedantic
596-
-Wno-c++11-compat
597-
-Wno-undef
598-
-Wno-reserved-id-macro
599-
-Wno-gnu-include-next
600-
-Wno-gcc-compat # For ignoring "'diagnose_if' is a clang extension" warnings
601-
-Wno-zero-as-null-pointer-constant # FIXME: Remove this and fix all occurrences.
602-
-Wno-deprecated-dynamic-exception-spec # For auto_ptr
603-
-Wno-sign-conversion
604-
-Wno-old-style-cast
605-
-Wno-deprecated # FIXME: Remove this and fix all occurrences.
606-
-Wno-shift-sign-overflow # FIXME: Why do we need this with clang-cl but not clang?
607-
-Wno-double-promotion # FIXME: remove me
608-
)
609-
endif()
610-
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
611-
target_add_compile_flags_if_supported(${target} PRIVATE
612-
-Wno-attributes
613-
-Wno-literal-suffix
614-
-Wno-c++14-compat
615-
-Wno-noexcept-type
616-
-Wno-suggest-override)
617-
endif()
618-
if (LIBCXX_ENABLE_WERROR)
619-
target_add_compile_flags_if_supported(${target} PRIVATE -Werror)
620-
target_add_compile_flags_if_supported(${target} PRIVATE -WX)
621-
else()
622-
# TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is
623-
# added elsewhere.
624-
target_add_compile_flags_if_supported(${target} PRIVATE -Wno-error)
625-
endif()
626-
if (LIBCXX_ENABLE_PEDANTIC)
627-
target_add_compile_flags_if_supported(${target} PRIVATE -pedantic)
628-
endif()
629-
endfunction()
630-
631567
# Exception flags =============================================================
632568
function(cxx_add_exception_flags target)
633569
if (LIBCXX_ENABLE_EXCEPTIONS)
@@ -910,7 +846,7 @@ endif()
910846
# Setup all common build flags =================================================
911847
function(cxx_add_common_build_flags target)
912848
cxx_add_basic_build_flags(${target})
913-
cxx_add_warning_flags(${target})
849+
cxx_add_warning_flags(${target} ${LIBCXX_ENABLE_WERROR} ${LIBCXX_ENABLE_PEDANTIC})
914850
cxx_add_windows_flags(${target})
915851
cxx_add_exception_flags(${target})
916852
cxx_add_rtti_flags(${target})

libcxxabi/CMakeLists.txt

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ option(LIBCXXABI_ENABLE_EXCEPTIONS
4444
"Provide support for exceptions in the runtime.
4545
When disabled, libc++abi does not support stack unwinding and other exceptions-related features." ON)
4646
option(LIBCXXABI_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
47-
option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
47+
option(LIBCXXABI_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
4848
option(LIBCXXABI_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
4949
option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF)
5050
option(LIBCXXABI_ENABLE_STATIC_UNWINDER "Statically link the LLVM unwinder." OFF)
@@ -279,41 +279,6 @@ add_definitions(-D_LIBCXXABI_BUILDING_LIBRARY)
279279
# it is being built as part of libcxx.
280280
add_definitions(-D_LIBCPP_BUILDING_LIBRARY)
281281

282-
add_compile_flags_if_supported(-Werror=return-type)
283-
284-
# Get warning flags
285-
add_compile_flags_if_supported(-W)
286-
add_compile_flags_if_supported(-Wall)
287-
add_compile_flags_if_supported(-Wchar-subscripts)
288-
add_compile_flags_if_supported(-Wconversion)
289-
add_compile_flags_if_supported(-Wmismatched-tags)
290-
add_compile_flags_if_supported(-Wmissing-braces)
291-
add_compile_flags_if_supported(-Wnewline-eof)
292-
add_compile_flags_if_supported(-Wunused-function)
293-
add_compile_flags_if_supported(-Wshadow)
294-
add_compile_flags_if_supported(-Wshorten-64-to-32)
295-
add_compile_flags_if_supported(-Wsign-compare)
296-
add_compile_flags_if_supported(-Wsign-conversion)
297-
add_compile_flags_if_supported(-Wstrict-aliasing=2)
298-
add_compile_flags_if_supported(-Wstrict-overflow=4)
299-
add_compile_flags_if_supported(-Wunused-parameter)
300-
add_compile_flags_if_supported(-Wunused-variable)
301-
add_compile_flags_if_supported(-Wwrite-strings)
302-
add_compile_flags_if_supported(-Wundef)
303-
304-
add_compile_flags_if_supported(-Wno-suggest-override)
305-
306-
if (LIBCXXABI_ENABLE_WERROR)
307-
add_compile_flags_if_supported(-Werror)
308-
add_compile_flags_if_supported(-WX)
309-
else()
310-
add_compile_flags_if_supported(-Wno-error)
311-
add_compile_flags_if_supported(-WX-)
312-
endif()
313-
if (LIBCXXABI_ENABLE_PEDANTIC)
314-
add_compile_flags_if_supported(-pedantic)
315-
endif()
316-
317282
# Get feature flags.
318283
add_compile_flags_if_supported(-fstrict-aliasing)
319284

libcxxabi/src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,11 @@ if (NOT TARGET pstl::ParallelSTL)
158158
message(STATUS "Could not find ParallelSTL, libc++abi will not attempt to use it but the build may fail if the libc++ in use needs it to be available.")
159159
endif()
160160

161+
include(WarningFlags)
162+
161163
# Build the shared library.
162164
add_library(cxxabi_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
165+
cxx_add_warning_flags(cxxabi_shared_objects ${LIBCXXABI_ENABLE_WERROR} ${LIBCXXABI_ENABLE_PEDANTIC})
163166
if (LIBCXXABI_USE_LLVM_UNWINDER)
164167
if (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY)
165168
target_link_libraries(cxxabi_shared_objects PUBLIC unwind_shared_objects) # propagate usage requirements
@@ -246,6 +249,7 @@ endif()
246249

247250
# Build the static library.
248251
add_library(cxxabi_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
252+
cxx_add_warning_flags(cxxabi_static_objects ${LIBCXXABI_ENABLE_WERROR} ${LIBCXXABI_ENABLE_PEDANTIC})
249253
if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
250254
target_link_libraries(cxxabi_static_objects PUBLIC unwind_static_objects) # propagate usage requirements
251255
target_sources(cxxabi_static_objects PUBLIC $<TARGET_OBJECTS:unwind_static_objects>)

libcxxabi/src/demangle/ItaniumDemangle.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "DemangleConfig.h"
2020
#include "StringView.h"
2121
#include "Utility.h"
22+
#include <__cxxabi_config.h>
2223
#include <algorithm>
2324
#include <cassert>
2425
#include <cctype>
@@ -30,6 +31,11 @@
3031
#include <type_traits>
3132
#include <utility>
3233

34+
#ifdef _LIBCXXABI_COMPILER_CLANG
35+
#pragma clang diagnostic push
36+
#pragma clang diagnostic ignored "-Wunused-template"
37+
#endif
38+
3339
DEMANGLE_NAMESPACE_BEGIN
3440

3541
template <class T, size_t N> class PODSmallVector {
@@ -5498,4 +5504,8 @@ struct ManglingParser : AbstractManglingParser<ManglingParser<Alloc>, Alloc> {
54985504

54995505
DEMANGLE_NAMESPACE_END
55005506

5507+
#ifdef _LIBCXXABI_COMPILER_CLANG
5508+
#pragma clang diagnostic pop
5509+
#endif
5510+
55015511
#endif // DEMANGLE_ITANIUMDEMANGLE_H

libunwind/CMakeLists.txt

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -169,28 +169,6 @@ if (LIBUNWIND_ENABLE_CET)
169169
endif()
170170
endif()
171171

172-
# Get warning flags
173-
add_compile_flags_if_supported(-W)
174-
add_compile_flags_if_supported(-Wall)
175-
add_compile_flags_if_supported(-Wchar-subscripts)
176-
add_compile_flags_if_supported(-Wconversion)
177-
add_compile_flags_if_supported(-Wmismatched-tags)
178-
add_compile_flags_if_supported(-Wmissing-braces)
179-
add_compile_flags_if_supported(-Wnewline-eof)
180-
add_compile_flags_if_supported(-Wno-unused-function)
181-
add_compile_flags_if_supported(-Wshadow)
182-
add_compile_flags_if_supported(-Wshorten-64-to-32)
183-
add_compile_flags_if_supported(-Wsign-compare)
184-
add_compile_flags_if_supported(-Wsign-conversion)
185-
add_compile_flags_if_supported(-Wstrict-aliasing=2)
186-
add_compile_flags_if_supported(-Wstrict-overflow=4)
187-
add_compile_flags_if_supported(-Wunused-parameter)
188-
add_compile_flags_if_supported(-Wunused-variable)
189-
add_compile_flags_if_supported(-Wwrite-strings)
190-
add_compile_flags_if_supported(-Wundef)
191-
192-
add_compile_flags_if_supported(-Wno-suggest-override)
193-
194172
if (WIN32)
195173
# The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT);
196174
# silence the warning instead of cluttering the headers (which aren't
@@ -199,18 +177,6 @@ if (WIN32)
199177
add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
200178
endif()
201179

202-
if (LIBUNWIND_ENABLE_WERROR)
203-
add_compile_flags_if_supported(-Werror)
204-
add_compile_flags_if_supported(-WX)
205-
else()
206-
add_compile_flags_if_supported(-Wno-error)
207-
add_compile_flags_if_supported(-WX-)
208-
endif()
209-
210-
if (LIBUNWIND_ENABLE_PEDANTIC)
211-
add_compile_flags_if_supported(-pedantic)
212-
endif()
213-
214180
# Get feature flags.
215181
# Exceptions
216182
# Catches C++ exceptions only and tells the compiler to assume that extern C

libunwind/src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,11 @@ set_property(SOURCE ${LIBUNWIND_C_SOURCES}
135135
# ease, but does not rely on C++ at runtime.
136136
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
137137

138+
include(WarningFlags)
139+
138140
# Build the shared library.
139141
add_library(unwind_shared_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
142+
cxx_add_warning_flags(unwind_shared_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})
140143
if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
141144
target_compile_options(unwind_shared_objects PRIVATE /GR-)
142145
else()
@@ -174,6 +177,7 @@ endif()
174177

175178
# Build the static library.
176179
add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
180+
cxx_add_warning_flags(unwind_static_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})
177181
if(CMAKE_C_COMPILER_ID STREQUAL MSVC)
178182
target_compile_options(unwind_static_objects PRIVATE /GR-)
179183
else()
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
include(HandleFlags)
2+
3+
# Warning flags ===============================================================
4+
function(cxx_add_warning_flags target enable_werror enable_pedantic)
5+
target_compile_definitions(${target} PUBLIC -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
6+
if (MSVC)
7+
# -W4 is the cl.exe/clang-cl equivalent of -Wall. (In cl.exe and clang-cl,
8+
# -Wall is equivalent to -Weverything in GCC style compiler drivers.)
9+
target_add_compile_flags_if_supported(${target} PRIVATE -W4)
10+
else()
11+
target_add_compile_flags_if_supported(${target} PRIVATE -Wall)
12+
endif()
13+
# TODO: Should -Wconversion be enabled?
14+
target_add_compile_flags_if_supported(${target} PRIVATE
15+
-Wall
16+
-Wextra
17+
-Wnewline-eof
18+
-Wshadow
19+
-Wwrite-strings
20+
-Wno-unused-parameter
21+
-Wno-long-long
22+
-Werror=return-type
23+
-Wextra-semi
24+
-Wundef
25+
-Wunused-template
26+
-Wformat-nonliteral
27+
)
28+
29+
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
30+
target_add_compile_flags_if_supported(${target} PRIVATE
31+
-Wno-user-defined-literals
32+
-Wno-covered-switch-default
33+
-Wno-suggest-override
34+
)
35+
if (LIBCXX_TARGETING_CLANG_CL)
36+
target_add_compile_flags_if_supported(${target} PRIVATE
37+
-Wno-c++98-compat
38+
-Wno-c++98-compat-pedantic
39+
-Wno-c++11-compat
40+
-Wno-undef
41+
-Wno-reserved-id-macro
42+
-Wno-gnu-include-next
43+
-Wno-gcc-compat # For ignoring "'diagnose_if' is a clang extension" warnings
44+
-Wno-zero-as-null-pointer-constant # FIXME: Remove this and fix all occurrences.
45+
-Wno-deprecated-dynamic-exception-spec # For auto_ptr
46+
-Wno-sign-conversion
47+
-Wno-old-style-cast
48+
-Wno-deprecated # FIXME: Remove this and fix all occurrences.
49+
-Wno-shift-sign-overflow # FIXME: Why do we need this with clang-cl but not clang?
50+
-Wno-double-promotion # FIXME: remove me
51+
)
52+
endif()
53+
54+
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
55+
56+
target_add_compile_flags_if_supported(${target} PRIVATE
57+
-Wstrict-aliasing=2
58+
-Wstrict-overflow=4
59+
-Wno-attributes
60+
-Wno-literal-suffix
61+
-Wno-c++14-compat
62+
-Wno-noexcept-type
63+
-Wno-suggest-override
64+
)
65+
66+
endif()
67+
if (${enable_werror})
68+
target_add_compile_flags_if_supported(${target} PRIVATE -Werror)
69+
target_add_compile_flags_if_supported(${target} PRIVATE -WX)
70+
else()
71+
# TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is
72+
# added elsewhere.
73+
target_add_compile_flags_if_supported(${target} PRIVATE -Wno-error)
74+
endif()
75+
if (${enable_pedantic})
76+
target_add_compile_flags_if_supported(${target} PRIVATE -pedantic)
77+
endif()
78+
endfunction()

0 commit comments

Comments
 (0)