🚧 update warnings flags

This commit is contained in:
Vladislav Nepogodin 2022-11-17 02:15:20 +04:00
parent 575dfa04af
commit 8084d28fb3
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
3 changed files with 91 additions and 15 deletions

View File

@ -1,5 +1,6 @@
function(set_project_warnings project_name)
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF)
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" ON)
option(ENABLE_HARD_WARNINGS "Enable HARD warnings for static ananlyzer" OFF)
set(MSVC_WARNINGS
/W4 # Baseline reasonable warnings
@ -46,7 +47,7 @@ function(set_project_warnings project_name)
-Wimplicit-fallthrough # warn on statements that fallthrough without an explicit annotation
)
if(WARNINGS_AS_ERRORS)
if(WARNINGS_AS_ERRORS AND NOT ENABLE_HARD_WARNINGS)
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
endif()
@ -72,8 +73,38 @@ function(set_project_warnings project_name)
-Wanalyzer-double-free
-Wanalyzer-malloc-leak
-Wanalyzer-use-after-free
## some more analyzer flags
-Wanalyzer-tainted-allocation-size
-Wanalyzer-use-of-uninitialized-value
-Wanalyzer-use-of-pointer-in-stale-stack-frame
-Wanalyzer-free-of-non-heap
-Wanalyzer-mismatching-deallocation
-Wanalyzer-null-dereference
-Wanalyzer-possible-null-dereference
)
if(ENABLE_HARD_WARNINGS)
set(GCC_WARNINGS
${GCC_WARNINGS}
-fanalyzer
-Wanalyzer-too-complex
## just for testing
-Wanalyzer-exposure-through-output-file
-Wanalyzer-file-leak
-Wanalyzer-null-argument
-Wanalyzer-possible-null-argument
-Wanalyzer-shift-count-negative
-Wanalyzer-shift-count-overflow
-Wanalyzer-stale-setjmp-buffer
-Wanalyzer-unsafe-call-within-signal-handler
-Wanalyzer-write-to-const
-Wanalyzer-write-to-string-literal
)
endif()
if(MSVC)
set(PROJECT_WARNINGS ${MSVC_WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")

View File

@ -25,11 +25,15 @@ if [[ $1 == "--help" ]]; then
cat<<EOF
Usage: configure.sh [options]
Options:
--help Display this information.
--buildtype=, -t= Specify build type.
--prefix= Specify install prefix.
--libdir= Specify lib directory.
--path=, -p= Specify build directory.
--help Display this information.
--buildtype=, -t= Specify build type.
--prefix= Specify install prefix.
--libdir= Specify lib directory.
--path=, -p= Specify build directory.
--use_gcc Use GCC compiler.
--enable_sanitizer_address Enable ASAN.
--enable_sanitizer_ub Enable UBSAN.
--enable_sanitizer_leak Enable LEAKSAN.
EOF
exit 0
fi
@ -39,6 +43,10 @@ _buildpath="build"
_prefix="/usr/local"
_libdir="lib"
_buildtype="RelWithDebInfo"
_use_clang=true
_sanitizer_address=OFF
_sanitizer_UB=OFF
_sanitizer_leak=OFF
for i in "$@"; do
case $i in
-t=*|--buildtype=*)
@ -57,24 +65,52 @@ for i in "$@"; do
_buildpath="${i#*=}"
shift # past argument=value
;;
--use_gcc)
_use_clang=false
shift # past argument=value
;;
--enable_sanitizer_address)
_sanitizer_address=ON
shift # past argument=value
;;
--enable_sanitizer_ub)
_sanitizer_UB=ON
shift # past argument=value
;;
--enable_sanitizer_leak)
_sanitizer_leak=ON
shift # past argument=value
;;
*)
# unknown option
;;
esac
done
export AR=llvm-ar
export CC=clang
export CXX=clang++
export NM=llvm-nm
export RANLIB=llvm-ranlib
if ${_use_clang}; then
export AR=llvm-ar
export CC=clang
export CXX=clang++
export NM=llvm-nm
export RANLIB=llvm-ranlib
fi
if command -v ninja &> /dev/null; then
_configure_flags+=('-GNinja')
fi
if command -v mold &> /dev/null; then
_configure_flags+=('-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=mold"')
fi
cmake -S . -B ${_buildpath}/${_buildtype} \
-GNinja \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=mold" \
-DENABLE_SANITIZER_ADDRESS=${_sanitizer_address} \
-DENABLE_SANITIZER_UNDEFINED_BEHAVIOR=${_sanitizer_UB} \
-DENABLE_SANITIZER_LEAK=${_sanitizer_leak} \
-DCMAKE_BUILD_TYPE=${_buildtype} \
-DCMAKE_INSTALL_PREFIX=${_prefix} \
-DCMAKE_INSTALL_LIBDIR=${_libdir}
-DCMAKE_INSTALL_LIBDIR=${_libdir} \
"${_configure_flags[@]}"
cat > build.sh <<EOF
#!/bin/bash

View File

@ -103,6 +103,15 @@ if cc.get_id() == 'gcc'
'-Wanalyzer-double-free',
'-Wanalyzer-malloc-leak',
'-Wanalyzer-use-after-free',
## some more analyzer flags
'-Wanalyzer-tainted-allocation-size',
'-Wanalyzer-use-of-uninitialized-value',
'-Wanalyzer-use-of-pointer-in-stale-stack-frame',
'-Wanalyzer-free-of-non-heap',
'-Wanalyzer-mismatching-deallocation',
'-Wanalyzer-null-dereference',
'-Wanalyzer-possible-null-dereference',
]
endif