Skip to content

Commit

Permalink
Deal with tons of warnings produced by Elbrus compiler
Browse files Browse the repository at this point in the history
Added a couple of CMake options to disable some warnings that
are produced by LCC while building separation and nbody.
Safe ones are disabled by default; potentially unsafe may be
disabled, but still enabled by default.
  • Loading branch information
makise-homura committed Jan 10, 2020
1 parent 2e23b05 commit 324c6aa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
34 changes: 32 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ if(MILKYWAY_IPHONE_APP)
add_definitions("-DMILKYWAY_IPHONE_APP")
endif()

option (DISABLE_SAFE_LCC_WARNINGS "Disable some of excess Elbrus compiler warnings" ON)
mark_as_advanced(DISABLE_SAFE_LCC_WARNINGS)

option (DISABLE_EXTRA_LCC_WARNINGS "Disable more Elbrus compiler warnings that may be unsafe" OFF)
mark_as_advanced(DISABLE_EXTRA_LCC_WARNINGS)

################################################################################

Expand Down Expand Up @@ -247,6 +252,31 @@ add_flag_if_supported("-xc99")
# #-Xanalyzer -analyzer-display-progress
# -Xanalyzer -analyzer-no-purge-dead)

if(DISABLE_SAFE_LCC_WARNINGS)
# These warnings are about completely safe situations
suppress_warning_if_supported("-Wno-alignment-reduction-ignored")
suppress_warning_if_supported("-Wno-unused-variable")
suppress_warning_if_supported("-Wno-unused-function")
suppress_warning_if_supported("-Wno-unused-parameter")
suppress_warning_if_supported("-Wno-comment")
suppress_warning_if_supported("-Wno-static-reference-in-c99-inline-function")
suppress_warning_if_supported("-Wno-reduced-alignment")
suppress_warning_if_supported("-Wno-inline")

if(DISABLE_EXTRA_LCC_WARNINGS)
# These warnings may probably lead to some unsafe situations,
# so we won't turn them off unless specifically noted
suppress_warning_if_supported("-Wno-maybe-uninitialized")
suppress_warning_if_supported("-Wno-invalid-pragma-parameter")
suppress_warning_if_supported("-Wno-bad-initializer-type")
suppress_warning_if_supported("-Wno-sign-compare")
suppress_warning_if_supported("-Wno-array-bounds")
suppress_warning_if_supported("-Wno-bad-return-value-type")
suppress_warning_if_supported("-Wno-implicit-function-declaration")
suppress_warning_if_supported("-Wno-invalid-builtin-arg")
endif()
endif()

CHECK_C_COMPILER_FLAG("-funswitch-loops" SUPPORTS_UNSWITCH_LOOPS)
if(SUPPORTS_UNSWITCH_LOOPS)
set(gcc_extra_flags "-fno-common -funswitch-loops ")
Expand Down Expand Up @@ -278,7 +308,7 @@ if(NOT DOUBLEPREC)
endif()

if(CMAKE_COMPILER_IS_GNUCC OR C_COMPILER_IS_CLANG)
foreach(flag ${gcc_extra_flags} ${gcc_warnings} ${extra_gcc_math_flags})
foreach(flag ${gcc_extra_flags} ${gcc_warnings} ${extra_gcc_math_flags} ${suppress_warning_flags})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
endforeach()
endif()
Expand All @@ -290,7 +320,7 @@ if(CMAKE_COMPILER_IS_GNUCC AND NOT C_COMPILER_IS_CLANG)
endif()

if(CMAKE_COMPILER_IS_GNUCC OR CXX_COMPILER_IS_CLANG)
foreach(flag ${gcc_extra_flags} ${gcc_warnings} ${extra_gcc_math_flags})
foreach(flag ${gcc_extra_flags} ${gcc_warnings} ${extra_gcc_math_flags} ${suppress_warning_flags})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endforeach()
endif()
Expand Down
9 changes: 9 additions & 0 deletions cmake_modules/CheckCFlag.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ function(add_flag_if_supported flagname)
endif()
endfunction()

# The ${suppress_warning_flags} variable is to be added after all other flags.
function(suppress_warning_if_supported flagname)
check_c_compiler_flag("${flagname}" HAVE_FLAG_${flagname})

if(${HAVE_FLAG_${flagname}})
set(suppress_warning_flags "${suppress_warning_flags} ${flagname}" PARENT_SCOPE)
endif()
endfunction()

function(append_supported_flags flags)
foreach(flag ${flags})
add_flag_if_supported(${flag})
Expand Down

0 comments on commit 324c6aa

Please sign in to comment.