From e0383324249e29ddc514a7fe904926d17df647e7 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 27 Mar 2020 18:35:23 +0000 Subject: [PATCH] gcc: support -fanalyzer static analysis Starting with gcc 10 (in fedora 32) there's a new static analyzer built into gcc you can enable with -fanalyzer. It doesn't slow compilation much, but it's a bit hit and miss, it only analyzes each compilation unit standalone so it reports issues that can never happen. Enable it if the option LWS_WITH_FANALYZER is enabled and cmake can see the actual compiler supports it. --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50b90e6c1..9253181c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,7 +166,7 @@ option(LWS_WITH_DETAILED_LATENCY "Record detailed latency stats for each read an option(LWS_WITH_UDP "Platform supports UDP" ON) option(LWS_WITH_SPAWN "Spawn subprocesses with piped stdin/out/stderr" OFF) option(LWS_WITH_FSMOUNT "Overlayfs and fallback mounting apis" OFF) - +option(LWS_WITH_FANALYZER "Enable gcc -fanalyzer if compiler supports" OFF) # # to use miniz, enable both LWS_WITH_ZLIB and LWS_WITH_MINIZ @@ -1724,6 +1724,9 @@ endif() if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG) include (CheckCCompilerFlag) CHECK_C_COMPILER_FLAG(-fvisibility=hidden LWS_HAVE_VISIBILITY) + if (LWS_WITH_FANALYZER) + CHECK_C_COMPILER_FLAG(-fanalyzer LWS_HAVE_FANALYZER) + endif() if (LWS_HAVE_VISIBILITY) set(VISIBILITY_FLAG -fvisibility=hidden) endif() @@ -1750,6 +1753,10 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG) set(CMAKE_C_FLAGS "-Wtype-limits ${CMAKE_C_FLAGS}" ) endif() + if (LWS_WITH_FANALYZER AND LWS_HAVE_FANALYZER) + set(CMAKE_C_FLAGS "-fanalyzer ${CMAKE_C_FLAGS}" ) + endif() + if (UNIX AND NOT LWS_PLAT_FREERTOS) set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wstrict-aliasing -Wuninitialized -Werror ${VISIBILITY_FLAG} -Wundef ${GCOV_FLAGS} ${CMAKE_C_FLAGS} ${ASAN_FLAGS}" ) else()