Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 04b98c1

Browse files
committed
[OpenMP] Turn on -Wall compiler warnings by default
Instead, maintain a list of disabled options to still build libomp and libomptarget without warnings. This includes -Wno-error and -Wno-pedantic to silence warnings that LLVM enables when building in-tree. I tested the following compilers: * Clang 6.0, 7.0, 8.0 * GCC 4.8.5 (CentOS 7), GCC 6, 7, 8, 9 * Intel Compiler 16, 17, 18, 19 RFC thread on openmp-dev mailing list: http://lists.llvm.org/pipermail/openmp-dev/2019-August/002668.html Differential Revision: https://reviews.llvm.org/D65867 git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@368999 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 923dcc5 commit 04b98c1

File tree

4 files changed

+59
-55
lines changed

4 files changed

+59
-55
lines changed

cmake/HandleOpenMPOptions.cmake

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if (${OPENMP_STANDALONE_BUILD})
1+
if (OPENMP_STANDALONE_BUILD)
22
# From HandleLLVMOptions.cmake
33
function(append_if condition value)
44
if (${condition})
@@ -9,10 +9,25 @@ if (${OPENMP_STANDALONE_BUILD})
99
endfunction()
1010
endif()
1111

12-
if (${OPENMP_ENABLE_WERROR})
12+
# MSVC and clang-cl in compatibility mode map -Wall to -Weverything.
13+
# TODO: LLVM adds /W4 instead, check if that works for the OpenMP runtimes.
14+
if (NOT MSVC)
15+
append_if(OPENMP_HAVE_WALL_FLAG "-Wall" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
16+
endif()
17+
if (OPENMP_ENABLE_WERROR)
1318
append_if(OPENMP_HAVE_WERROR_FLAG "-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
1419
endif()
1520

21+
# Additional warnings that are not enabled by -Wall.
22+
append_if(OPENMP_HAVE_WCAST_QUAL_FLAG "-Wcast-qual" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
23+
append_if(OPENMP_HAVE_WFORMAT_PEDANTIC_FLAG "-Wformat-pedantic" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
24+
append_if(OPENMP_HAVE_WSIGN_COMPARE_FLAG "-Wsign-compare" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
25+
26+
# Warnings that we want to disable because they are too verbose or fragile.
27+
append_if(OPENMP_HAVE_WNO_EXTRA_FLAG "-Wno-extra" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
28+
append_if(OPENMP_HAVE_WNO_PEDANTIC_FLAG "-Wno-pedantic" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
29+
append_if(OPENMP_HAVE_WNO_MAYBE_UNINITIALIZED_FLAG "-Wno-maybe-uninitialized" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
30+
1631
append_if(OPENMP_HAVE_STD_GNUPP11_FLAG "-std=gnu++11" CMAKE_CXX_FLAGS)
1732
if (NOT OPENMP_HAVE_STD_GNUPP11_FLAG)
1833
append_if(OPENMP_HAVE_STD_CPP11_FLAG "-std=c++11" CMAKE_CXX_FLAGS)

cmake/config-ix.cmake

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
include(CheckCCompilerFlag)
21
include(CheckCXXCompilerFlag)
32

4-
check_c_compiler_flag(-Werror OPENMP_HAVE_WERROR_FLAG)
3+
check_cxx_compiler_flag(-Wall OPENMP_HAVE_WALL_FLAG)
4+
check_cxx_compiler_flag(-Werror OPENMP_HAVE_WERROR_FLAG)
5+
6+
# Additional warnings that are not enabled by -Wall.
7+
check_cxx_compiler_flag(-Wcast-qual OPENMP_HAVE_WCAST_QUAL_FLAG)
8+
check_cxx_compiler_flag(-Wformat-pedantic OPENMP_HAVE_WFORMAT_PEDANTIC_FLAG)
9+
check_cxx_compiler_flag(-Wsign-compare OPENMP_HAVE_WSIGN_COMPARE_FLAG)
10+
11+
# Warnings that we want to disable because they are too verbose or fragile.
12+
check_cxx_compiler_flag(-Wno-extra OPENMP_HAVE_WNO_EXTRA_FLAG)
13+
check_cxx_compiler_flag(-Wno-pedantic OPENMP_HAVE_WNO_PEDANTIC_FLAG)
14+
check_cxx_compiler_flag(-Wno-maybe-uninitialized OPENMP_HAVE_WNO_MAYBE_UNINITIALIZED_FLAG)
515

616
check_cxx_compiler_flag(-std=gnu++11 OPENMP_HAVE_STD_GNUPP11_FLAG)
717
check_cxx_compiler_flag(-std=c++11 OPENMP_HAVE_STD_CPP11_FLAG)

runtime/cmake/LibompHandleFlags.cmake

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,24 @@ macro(libomp_setup_flags flags)
2222
endif()
2323
endmacro()
2424

25-
# Gets flags common to both the C and C++ compiler
26-
function(libomp_get_c_and_cxxflags_common flags)
25+
# C++ compiler flags
26+
function(libomp_get_cxxflags cxxflags)
2727
set(flags_local)
2828
libomp_append(flags_local -fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG)
2929
libomp_append(flags_local -fno-rtti LIBOMP_HAVE_FNO_RTTI_FLAG)
30-
if(${OPENMP_STANDALONE_BUILD})
31-
libomp_append(flags_local -Wsign-compare LIBOMP_HAVE_WNO_SIGN_COMPARE_FLAG)
32-
libomp_append(flags_local -Wunused-function LIBOMP_HAVE_WNO_UNUSED_FUNCTION_FLAG)
33-
libomp_append(flags_local -Wunused-local-typedef LIBOMP_HAVE_WNO_UNUSED_LOCAL_TYPEDEF_FLAG)
34-
libomp_append(flags_local -Wunused-value LIBOMP_HAVE_WNO_UNUSED_VALUE_FLAG)
35-
libomp_append(flags_local -Wunused-variable LIBOMP_HAVE_WNO_UNUSED_VARIABLE_FLAG)
36-
libomp_append(flags_local -Wdeprecated-register LIBOMP_HAVE_WNO_DEPRECATED_REGISTER_FLAG)
37-
libomp_append(flags_local -Wunknown-pragmas LIBOMP_HAVE_WNO_UNKNOWN_PRAGMAS_FLAG)
38-
libomp_append(flags_local -Wcomment LIBOMP_HAVE_WNO_COMMENT_FLAG)
39-
libomp_append(flags_local -Wself-assign LIBOMP_HAVE_WNO_SELF_ASSIGN_FLAG)
40-
libomp_append(flags_local -Wformat-pedantic LIBOMP_HAVE_WNO_FORMAT_PEDANTIC_FLAG)
41-
endif()
42-
libomp_append(flags_local -Wno-switch LIBOMP_HAVE_WNO_SWITCH_FLAG)
30+
libomp_append(flags_local -Wno-class-memaccess LIBOMP_HAVE_WNO_CLASS_MEMACCESS_FLAG)
4331
libomp_append(flags_local -Wno-covered-switch-default LIBOMP_HAVE_WNO_COVERED_SWITCH_DEFAULT_FLAG)
44-
libomp_append(flags_local -Wno-gnu-anonymous-struct LIBOMP_HAVE_WNO_GNU_ANONYMOUS_STRUCT_FLAG)
45-
libomp_append(flags_local -Wno-missing-field-initializers LIBOMP_HAVE_WNO_MISSING_FIELD_INITIALIZERS_FLAG)
32+
libomp_append(flags_local -Wno-frame-address LIBOMP_HAVE_WNO_FRAME_ADDRESS_FLAG)
33+
libomp_append(flags_local -Wno-implicit-fallthrough LIBOMP_HAVE_WNO_IMPLICIT_FALLTHROUGH_FLAG)
34+
libomp_append(flags_local -Wno-int-in-bool-context LIBOMP_HAVE_WNO_INT_IN_BOOL_CONTEXT_FLAG)
4635
libomp_append(flags_local -Wno-missing-braces LIBOMP_HAVE_WNO_MISSING_BRACES_FLAG)
47-
libomp_append(flags_local -Wno-vla-extension LIBOMP_HAVE_WNO_VLA_EXTENSION_FLAG)
36+
libomp_append(flags_local -Wno-parentheses LIBOMP_HAVE_WNO_PARENTHESES_FLAG)
37+
libomp_append(flags_local -Wno-strict-aliasing LIBOMP_HAVE_WNO_STRICT_ALIASING_FLAG)
4838
libomp_append(flags_local -Wstringop-overflow=0 LIBOMP_HAVE_WSTRINGOP_OVERFLOW_FLAG)
39+
libomp_append(flags_local -Wno-stringop-truncation LIBOMP_HAVE_WNO_STRINGOP_TRUNCATION_FLAG)
40+
libomp_append(flags_local -Wno-switch LIBOMP_HAVE_WNO_SWITCH_FLAG)
41+
libomp_append(flags_local -Wno-uninitialized LIBOMP_HAVE_WNO_UNINITIALIZED_FLAG)
42+
libomp_append(flags_local -Wno-unused-but-set-variable LIBOMP_HAVE_WNO_UNUSED_BUT_SET_VARIABLE_FLAG)
4943
libomp_append(flags_local /GS LIBOMP_HAVE_GS_FLAG)
5044
libomp_append(flags_local /EHsc LIBOMP_HAVE_EHSC_FLAG)
5145
libomp_append(flags_local /Oy- LIBOMP_HAVE_OY__FLAG)
@@ -71,17 +65,7 @@ function(libomp_get_c_and_cxxflags_common flags)
7165
libomp_append(flags_local -ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG)
7266
libomp_append(flags_local "-opt-streaming-stores never" LIBOMP_HAVE_OPT_STREAMING_STORES_FLAG)
7367
endif()
74-
set(${flags} ${flags_local} PARENT_SCOPE)
75-
endfunction()
76-
77-
# C++ compiler flags
78-
function(libomp_get_cxxflags cxxflags)
79-
set(cxxflags_local)
80-
libomp_get_c_and_cxxflags_common(cxxflags_local)
81-
if(${OPENMP_STANDALONE_BUILD})
82-
libomp_append(cxxflags_local -Wcast-qual LIBOMP_HAVE_WCAST_QUAL_FLAG)
83-
endif()
84-
set(cxxflags_local ${cxxflags_local} ${LIBOMP_CXXFLAGS})
68+
set(cxxflags_local ${flags_local} ${LIBOMP_CXXFLAGS})
8569
libomp_setup_flags(cxxflags_local)
8670
set(${cxxflags} ${cxxflags_local} PARENT_SCOPE)
8771
endfunction()

runtime/cmake/config-ix.cmake

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,24 @@ function(libomp_check_architecture_flag flag retval)
4545
set(${retval} ${${retval}} PARENT_SCOPE)
4646
endfunction()
4747

48-
# Checking C, CXX, Linker Flags
48+
# Checking CXX, Linker Flags
4949
check_cxx_compiler_flag(-fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG)
5050
check_cxx_compiler_flag(-fno-rtti LIBOMP_HAVE_FNO_RTTI_FLAG)
51-
check_cxx_compiler_flag(-Wcast-qual LIBOMP_HAVE_WCAST_QUAL_FLAG)
52-
check_c_compiler_flag(-Wunused-function LIBOMP_HAVE_WNO_UNUSED_FUNCTION_FLAG)
53-
check_c_compiler_flag(-Wunused-local-typedef LIBOMP_HAVE_WNO_UNUSED_LOCAL_TYPEDEF_FLAG)
54-
check_c_compiler_flag(-Wunused-value LIBOMP_HAVE_WNO_UNUSED_VALUE_FLAG)
55-
check_c_compiler_flag(-Wunused-variable LIBOMP_HAVE_WNO_UNUSED_VARIABLE_FLAG)
56-
check_c_compiler_flag(-Wswitch LIBOMP_HAVE_WNO_SWITCH_FLAG)
57-
check_c_compiler_flag(-Wcovered-switch-default LIBOMP_HAVE_WNO_COVERED_SWITCH_DEFAULT_FLAG)
58-
check_c_compiler_flag(-Wdeprecated-register LIBOMP_HAVE_WNO_DEPRECATED_REGISTER_FLAG)
59-
check_c_compiler_flag(-Wsign-compare LIBOMP_HAVE_WNO_SIGN_COMPARE_FLAG)
60-
check_c_compiler_flag(-Wgnu-anonymous-struct LIBOMP_HAVE_WNO_GNU_ANONYMOUS_STRUCT_FLAG)
61-
check_c_compiler_flag(-Wunknown-pragmas LIBOMP_HAVE_WNO_UNKNOWN_PRAGMAS_FLAG)
62-
check_c_compiler_flag(-Wmissing-field-initializers LIBOMP_HAVE_WNO_MISSING_FIELD_INITIALIZERS_FLAG)
63-
check_c_compiler_flag(-Wmissing-braces LIBOMP_HAVE_WNO_MISSING_BRACES_FLAG)
64-
check_c_compiler_flag(-Wcomment LIBOMP_HAVE_WNO_COMMENT_FLAG)
65-
check_c_compiler_flag(-Wself-assign LIBOMP_HAVE_WNO_SELF_ASSIGN_FLAG)
66-
check_c_compiler_flag(-Wvla-extension LIBOMP_HAVE_WNO_VLA_EXTENSION_FLAG)
67-
check_c_compiler_flag(-Wformat-pedantic LIBOMP_HAVE_WNO_FORMAT_PEDANTIC_FLAG)
68-
check_c_compiler_flag(-Wstringop-overflow=0 LIBOMP_HAVE_WSTRINGOP_OVERFLOW_FLAG)
69-
check_c_compiler_flag(-msse2 LIBOMP_HAVE_MSSE2_FLAG)
70-
check_c_compiler_flag(-ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG)
51+
check_cxx_compiler_flag(-Wno-class-memaccess LIBOMP_HAVE_WNO_CLASS_MEMACCESS_FLAG)
52+
check_cxx_compiler_flag(-Wno-covered-switch-default LIBOMP_HAVE_WNO_COVERED_SWITCH_DEFAULT_FLAG)
53+
check_cxx_compiler_flag(-Wno-frame-address LIBOMP_HAVE_WNO_FRAME_ADDRESS_FLAG)
54+
check_cxx_compiler_flag(-Wno-implicit-fallthrough LIBOMP_HAVE_WNO_IMPLICIT_FALLTHROUGH_FLAG)
55+
check_cxx_compiler_flag(-Wno-int-in-bool-context LIBOMP_HAVE_WNO_INT_IN_BOOL_CONTEXT_FLAG)
56+
check_cxx_compiler_flag(-Wno-missing-braces LIBOMP_HAVE_WNO_MISSING_BRACES_FLAG)
57+
check_cxx_compiler_flag(-Wno-parentheses LIBOMP_HAVE_WNO_PARENTHESES_FLAG)
58+
check_cxx_compiler_flag(-Wno-strict-aliasing LIBOMP_HAVE_WNO_STRICT_ALIASING_FLAG)
59+
check_cxx_compiler_flag(-Wstringop-overflow=0 LIBOMP_HAVE_WSTRINGOP_OVERFLOW_FLAG)
60+
check_cxx_compiler_flag(-Wno-stringop-truncation LIBOMP_HAVE_WNO_STRINGOP_TRUNCATION_FLAG)
61+
check_cxx_compiler_flag(-Wno-switch LIBOMP_HAVE_WNO_SWITCH_FLAG)
62+
check_cxx_compiler_flag(-Wno-uninitialized LIBOMP_HAVE_WNO_UNINITIALIZED_FLAG)
63+
check_cxx_compiler_flag(-Wno-unused-but-set-variable LIBOMP_HAVE_WNO_UNUSED_BUT_SET_VARIABLE_FLAG)
64+
check_cxx_compiler_flag(-msse2 LIBOMP_HAVE_MSSE2_FLAG)
65+
check_cxx_compiler_flag(-ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG)
7166
libomp_check_architecture_flag(-mmic LIBOMP_HAVE_MMIC_FLAG)
7267
libomp_check_architecture_flag(-m32 LIBOMP_HAVE_M32_FLAG)
7368
if(WIN32)
@@ -79,7 +74,7 @@ if(WIN32)
7974
check_cxx_compiler_flag(/arch:SSE2 LIBOMP_HAVE_ARCH_SSE2_FLAG)
8075
check_cxx_compiler_flag(/Qsafeseh LIBOMP_HAVE_QSAFESEH_FLAG)
8176
endif()
82-
check_c_compiler_flag(-mrtm LIBOMP_HAVE_MRTM_FLAG)
77+
check_cxx_compiler_flag(-mrtm LIBOMP_HAVE_MRTM_FLAG)
8378
# It is difficult to create a dummy masm assembly file
8479
# and then check the MASM assembler to see if these flags exist and work,
8580
# so we assume they do for Windows.

0 commit comments

Comments
 (0)