Skip to content

Commit 93c011e

Browse files
committed
[OpenMP] Fix detecting warning options for GCC
If testing for a warning option like -Wno-<foo> with GCC, GCC won't print any diagnostic at all, leading to the options being accepted incorrectly. However later, if compiling a file that actually prints another warning, GCC will also print warnings about these -Wno-<foo> options being unrecognized. This avoids warning spam like this, for every OpenMP source file that produces build warnings with GCC: cc1plus: warning: unrecognized command line option ‘-Wno-int-to-void-pointer-cast’ cc1plus: warning: unrecognized command line option ‘-Wno-return-type-c-linkage’ cc1plus: warning: unrecognized command line option ‘-Wno-covered-switch-default’ cc1plus: warning: unrecognized command line option ‘-Wno-enum-constexpr-conversion’ This matches how such warning options are detected and added in llvm/cmake/modules/HandleLLVMOptions.cmake, e.g. like this: check_cxx_compiler_flag("-Wclass-memaccess" CXX_SUPPORTS_CLASS_MEMACCESS_FLAG) append_if(CXX_SUPPORTS_CLASS_MEMACCESS_FLAG "-Wno-class-memaccess" CMAKE_CXX_FLAGS) This also matches how LLDB warning options were restructured for GCC compatibility in e546bbf. Differential Revision: https://reviews.llvm.org/D139922
1 parent 10d34f5 commit 93c011e

File tree

4 files changed

+52
-28
lines changed

4 files changed

+52
-28
lines changed

openmp/cmake/HandleOpenMPOptions.cmake

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ append_if(OPENMP_HAVE_WIMPLICIT_FALLTHROUGH_FLAG "-Wimplicit-fallthrough" CMAKE_
2525
append_if(OPENMP_HAVE_WSIGN_COMPARE_FLAG "-Wsign-compare" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
2626

2727
# Warnings that we want to disable because they are too verbose or fragile.
28-
append_if(OPENMP_HAVE_WNO_ENUM_CONSTEXPR_CONVERSION_FLAG "-Wno-enum-constexpr-conversion" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
29-
append_if(OPENMP_HAVE_WNO_EXTRA_FLAG "-Wno-extra" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
30-
append_if(OPENMP_HAVE_WNO_PEDANTIC_FLAG "-Wno-pedantic" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
31-
append_if(OPENMP_HAVE_WNO_MAYBE_UNINITIALIZED_FLAG "-Wno-maybe-uninitialized" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
28+
29+
# GCC silently accepts any -Wno-<foo> option, but warns about those options
30+
# being unrecognized only if the compilation triggers other warnings to be
31+
# printed. Therefore, check for whether the compiler supports options in the
32+
# form -W<foo>, and if supported, add the corresponding -Wno-<foo> option.
33+
34+
append_if(OPENMP_HAVE_WENUM_CONSTEXPR_CONVERSION_FLAG "-Wno-enum-constexpr-conversion" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
35+
append_if(OPENMP_HAVE_WEXTRA_FLAG "-Wno-extra" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
36+
append_if(OPENMP_HAVE_WPEDANTIC_FLAG "-Wno-pedantic" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
37+
append_if(OPENMP_HAVE_WMAYBE_UNINITIALIZED_FLAG "-Wno-maybe-uninitialized" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
3238

3339
append_if(OPENMP_HAVE_STD_CPP17_FLAG "-std=c++17" CMAKE_CXX_FLAGS)

openmp/cmake/config-ix.cmake

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ check_cxx_compiler_flag(-Wimplicit-fallthrough OPENMP_HAVE_WIMPLICIT_FALLTHROUGH
2626
check_cxx_compiler_flag(-Wsign-compare OPENMP_HAVE_WSIGN_COMPARE_FLAG)
2727

2828
# Warnings that we want to disable because they are too verbose or fragile.
29-
check_cxx_compiler_flag(-Wno-enum-constexpr-conversion OPENMP_HAVE_WNO_ENUM_CONSTEXPR_CONVERSION_FLAG)
30-
check_cxx_compiler_flag(-Wno-extra OPENMP_HAVE_WNO_EXTRA_FLAG)
31-
check_cxx_compiler_flag(-Wno-pedantic OPENMP_HAVE_WNO_PEDANTIC_FLAG)
32-
check_cxx_compiler_flag(-Wno-maybe-uninitialized OPENMP_HAVE_WNO_MAYBE_UNINITIALIZED_FLAG)
29+
30+
# GCC silently accepts any -Wno-<foo> option, but warns about those options
31+
# being unrecognized only if the compilation triggers other warnings to be
32+
# printed. Therefore, check for whether the compiler supports options in the
33+
# form -W<foo>, and if supported, add the corresponding -Wno-<foo> option.
34+
35+
check_cxx_compiler_flag(-Wenum-constexpr-conversion OPENMP_HAVE_WENUM_CONSTEXPR_CONVERSION_FLAG)
36+
check_cxx_compiler_flag(-Wextra OPENMP_HAVE_WEXTRA_FLAG)
37+
check_cxx_compiler_flag(-Wpedantic OPENMP_HAVE_WPEDANTIC_FLAG)
38+
check_cxx_compiler_flag(-Wmaybe-uninitialized OPENMP_HAVE_WMAYBE_UNINITIALIZED_FLAG)
3339

3440
check_cxx_compiler_flag(-std=c++17 OPENMP_HAVE_STD_CPP17_FLAG)

openmp/runtime/cmake/LibompHandleFlags.cmake

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,25 @@ endmacro()
2525
# C++ compiler flags
2626
function(libomp_get_cxxflags cxxflags)
2727
set(flags_local)
28+
29+
# GCC silently accepts any -Wno-<foo> option, but warns about those options
30+
# being unrecognized only if the compilation triggers other warnings to be
31+
# printed. Therefore, check for whether the compiler supports options in the
32+
# form -W<foo>, and if supported, add the corresponding -Wno-<foo> option.
33+
2834
libomp_append(flags_local -fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG)
2935
libomp_append(flags_local -fno-rtti LIBOMP_HAVE_FNO_RTTI_FLAG)
30-
libomp_append(flags_local -Wno-class-memaccess LIBOMP_HAVE_WNO_CLASS_MEMACCESS_FLAG)
31-
libomp_append(flags_local -Wno-covered-switch-default LIBOMP_HAVE_WNO_COVERED_SWITCH_DEFAULT_FLAG)
32-
libomp_append(flags_local -Wno-frame-address LIBOMP_HAVE_WNO_FRAME_ADDRESS_FLAG)
33-
libomp_append(flags_local -Wno-strict-aliasing LIBOMP_HAVE_WNO_STRICT_ALIASING_FLAG)
36+
libomp_append(flags_local -Wno-class-memaccess LIBOMP_HAVE_WCLASS_MEMACCESS_FLAG)
37+
libomp_append(flags_local -Wno-covered-switch-default LIBOMP_HAVE_WCOVERED_SWITCH_DEFAULT_FLAG)
38+
libomp_append(flags_local -Wno-frame-address LIBOMP_HAVE_WFRAME_ADDRESS_FLAG)
39+
libomp_append(flags_local -Wno-strict-aliasing LIBOMP_HAVE_WSTRICT_ALIASING_FLAG)
3440
libomp_append(flags_local -Wstringop-overflow=0 LIBOMP_HAVE_WSTRINGOP_OVERFLOW_FLAG)
35-
libomp_append(flags_local -Wno-stringop-truncation LIBOMP_HAVE_WNO_STRINGOP_TRUNCATION_FLAG)
36-
libomp_append(flags_local -Wno-switch LIBOMP_HAVE_WNO_SWITCH_FLAG)
37-
libomp_append(flags_local -Wno-uninitialized LIBOMP_HAVE_WNO_UNINITIALIZED_FLAG)
38-
libomp_append(flags_local -Wno-return-type-c-linkage LIBOMP_HAVE_WNO_RETURN_TYPE_C_LINKAGE_FLAG)
39-
libomp_append(flags_local -Wno-cast-qual LIBOMP_HAVE_WNO_CAST_QUAL_FLAG)
40-
libomp_append(flags_local -Wno-int-to-void-pointer-cast LIBOMP_HAVE_WNO_INT_TO_VOID_POINTER_CAST_FLAG)
41+
libomp_append(flags_local -Wno-stringop-truncation LIBOMP_HAVE_WSTRINGOP_TRUNCATION_FLAG)
42+
libomp_append(flags_local -Wno-switch LIBOMP_HAVE_WSWITCH_FLAG)
43+
libomp_append(flags_local -Wno-uninitialized LIBOMP_HAVE_WUNINITIALIZED_FLAG)
44+
libomp_append(flags_local -Wno-return-type-c-linkage LIBOMP_HAVE_WRETURN_TYPE_C_LINKAGE_FLAG)
45+
libomp_append(flags_local -Wno-cast-qual LIBOMP_HAVE_WCAST_QUAL_FLAG)
46+
libomp_append(flags_local -Wno-int-to-void-pointer-cast LIBOMP_HAVE_WINT_TO_VOID_POINTER_CAST_FLAG)
4147
# libomp_append(flags_local -Wconversion LIBOMP_HAVE_WCONVERSION_FLAG)
4248
libomp_append(flags_local /GS LIBOMP_HAVE_GS_FLAG)
4349
libomp_append(flags_local /EHsc LIBOMP_HAVE_EHSC_FLAG)

openmp/runtime/cmake/config-ix.cmake

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,25 @@ function(libomp_check_architecture_flag flag retval)
4848
endfunction()
4949

5050
# Checking CXX, Linker Flags
51+
52+
# GCC silently accepts any -Wno-<foo> option, but warns about those options
53+
# being unrecognized only if the compilation triggers other warnings to be
54+
# printed. Therefore, check for whether the compiler supports options in the
55+
# form -W<foo>, and if supported, add the corresponding -Wno-<foo> option.
56+
5157
check_cxx_compiler_flag(-fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG)
5258
check_cxx_compiler_flag(-fno-rtti LIBOMP_HAVE_FNO_RTTI_FLAG)
53-
check_cxx_compiler_flag(-Wno-class-memaccess LIBOMP_HAVE_WNO_CLASS_MEMACCESS_FLAG)
54-
check_cxx_compiler_flag(-Wno-covered-switch-default LIBOMP_HAVE_WNO_COVERED_SWITCH_DEFAULT_FLAG)
55-
check_cxx_compiler_flag(-Wno-frame-address LIBOMP_HAVE_WNO_FRAME_ADDRESS_FLAG)
56-
check_cxx_compiler_flag(-Wno-strict-aliasing LIBOMP_HAVE_WNO_STRICT_ALIASING_FLAG)
59+
check_cxx_compiler_flag(-Wclass-memaccess LIBOMP_HAVE_WCLASS_MEMACCESS_FLAG)
60+
check_cxx_compiler_flag(-Wcovered-switch-default LIBOMP_HAVE_WCOVERED_SWITCH_DEFAULT_FLAG)
61+
check_cxx_compiler_flag(-Wframe-address LIBOMP_HAVE_WFRAME_ADDRESS_FLAG)
62+
check_cxx_compiler_flag(-Wstrict-aliasing LIBOMP_HAVE_WSTRICT_ALIASING_FLAG)
5763
check_cxx_compiler_flag(-Wstringop-overflow=0 LIBOMP_HAVE_WSTRINGOP_OVERFLOW_FLAG)
58-
check_cxx_compiler_flag(-Wno-stringop-truncation LIBOMP_HAVE_WNO_STRINGOP_TRUNCATION_FLAG)
59-
check_cxx_compiler_flag(-Wno-switch LIBOMP_HAVE_WNO_SWITCH_FLAG)
60-
check_cxx_compiler_flag(-Wno-uninitialized LIBOMP_HAVE_WNO_UNINITIALIZED_FLAG)
61-
check_cxx_compiler_flag(-Wno-return-type-c-linkage LIBOMP_HAVE_WNO_RETURN_TYPE_C_LINKAGE_FLAG)
62-
check_cxx_compiler_flag(-Wno-cast-qual LIBOMP_HAVE_WNO_CAST_QUAL_FLAG)
63-
check_cxx_compiler_flag(-Wno-int-to-void-pointer-cast LIBOMP_HAVE_WNO_INT_TO_VOID_POINTER_CAST_FLAG)
64+
check_cxx_compiler_flag(-Wstringop-truncation LIBOMP_HAVE_WSTRINGOP_TRUNCATION_FLAG)
65+
check_cxx_compiler_flag(-Wswitch LIBOMP_HAVE_WSWITCH_FLAG)
66+
check_cxx_compiler_flag(-Wuninitialized LIBOMP_HAVE_WUNINITIALIZED_FLAG)
67+
check_cxx_compiler_flag(-Wreturn-type-c-linkage LIBOMP_HAVE_WRETURN_TYPE_C_LINKAGE_FLAG)
68+
check_cxx_compiler_flag(-Wcast-qual LIBOMP_HAVE_WCAST_QUAL_FLAG)
69+
check_cxx_compiler_flag(-Wint-to-void-pointer-cast LIBOMP_HAVE_WINT_TO_VOID_POINTER_CAST_FLAG)
6470
# check_cxx_compiler_flag(-Wconversion LIBOMP_HAVE_WCONVERSION_FLAG)
6571
check_cxx_compiler_flag(-msse2 LIBOMP_HAVE_MSSE2_FLAG)
6672
check_cxx_compiler_flag(-ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG)

0 commit comments

Comments
 (0)