Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / runtimes / cmake / Modules / WarningFlags.cmake
blobd06409841dc9df1a182e2043100069fd3399e073
1 include(HandleFlags)
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       -Wextra
16       -Wnewline-eof
17       -Wshadow
18       -Wwrite-strings
19       -Wno-unused-parameter
20       -Wno-long-long
21       -Werror=return-type
22       -Wextra-semi
23       -Wundef
24       -Wunused-template
25       -Wformat-nonliteral
26       )
28   if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
29     target_add_compile_flags_if_supported(${target} PRIVATE
30       -Wno-user-defined-literals
31       -Wno-covered-switch-default
32       -Wno-suggest-override
33     )
34     if (LIBCXX_TARGETING_CLANG_CL)
35       target_add_compile_flags_if_supported(${target} PRIVATE
36         -Wno-c++98-compat
37         -Wno-c++98-compat-pedantic
38         -Wno-c++11-compat
39         -Wno-undef
40         -Wno-reserved-id-macro
41         -Wno-gnu-include-next
42         -Wno-gcc-compat # For ignoring "'diagnose_if' is a clang extension" warnings
43         -Wno-zero-as-null-pointer-constant # FIXME: Remove this and fix all occurrences.
44         -Wno-deprecated-dynamic-exception-spec # For auto_ptr
45         -Wno-sign-conversion
46         -Wno-old-style-cast
47         -Wno-deprecated # FIXME: Remove this and fix all occurrences.
48         -Wno-shift-sign-overflow # FIXME: Why do we need this with clang-cl but not clang?
49         -Wno-double-promotion # FIXME: remove me
50       )
51     endif()
53   elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
55     target_add_compile_flags_if_supported(${target} PRIVATE
56       -Wstrict-aliasing=2
57       -Wstrict-overflow=4
58       -Wno-attributes
59       -Wno-literal-suffix
60       -Wno-c++14-compat
61       -Wno-noexcept-type
62       -Wno-suggest-override
63       )
65   endif()
66   if (${enable_werror})
67     target_add_compile_flags_if_supported(${target} PRIVATE -Werror)
68     target_add_compile_flags_if_supported(${target} PRIVATE -WX)
69   else()
70     # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is
71     # added elsewhere.
72     target_add_compile_flags_if_supported(${target} PRIVATE -Wno-error)
73   endif()
74   if (${enable_pedantic})
75     target_add_compile_flags_if_supported(${target} PRIVATE -pedantic)
76   endif()
77 endfunction()