Skip to content

Commit ac1aeae

Browse files
committed
[CMake] Fix Clang builds
In #1130, a new C++ flag was added: `-Wno-maybe-uninitialized`. This flag is GCC-specific, i.e. it is not supported by e.g. Clang. The following warning is issued by Clang when trying to use it: ``` warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean '-Wno-uninitialized'? [-Wunknown-warning-option] ``` This flag was added for all compilers for which `LLVM_COMPILER_IS_GCC_COMPATIBLE` is `true`. With Clang being considered as GCC-compatible [1] and `-Werror` being set by default in LLVM Flang, the aforementioned change causes build failures when using Clang. This patch works around it by making sure that this flag is only added when the compiler used to build Flang does support it. [1] See the current implementation of DetermineGCCCompatible.cmake
1 parent 9979896 commit ac1aeae

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

flang/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,14 @@ if (FLANG_ENABLE_WERROR)
328328
if ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
329329
append("-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
330330
append("-Wno-error" CMAKE_REQUIRED_FLAGS)
331-
append("-Wno-maybe-uninitialized" CMAKE_CXX_FLAGS)
331+
332+
# This is GCC-specific workaround for an issue described in
333+
# https://github.com/flang-compiler/f18-llvm-project/pull/1130
334+
check_cxx_compiler_flag("-Wno-maybe-uninitialized" CXX_SUPPORTS_MAYBE_UNITIALIZED_FLAG)
335+
if (CXX_SUPPORTS_MAYBE_UNITIALIZED_FLAG)
336+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-maybe-uninitialized")
337+
endif()
338+
332339
endif( LLVM_COMPILER_IS_GCC_COMPATIBLE )
333340
if (NOT LLVM_ENABLE_WERROR)
334341
message(WARNING "FLANG_ENABLE_WERROR setting is different from LLVM_ENABLE_WERROR.")

0 commit comments

Comments
 (0)