From c46a284bf3d5101d9a090ef0ad06bb8c7a122ab9 Mon Sep 17 00:00:00 2001 From: moelksasbyahmed Date: Tue, 27 Jan 2026 13:14:41 +0200 Subject: [PATCH 1/5] adding cmake support for gcc -fanalyzer --- cmake/celix_project/CelixProject.cmake | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmake/celix_project/CelixProject.cmake b/cmake/celix_project/CelixProject.cmake index 8f231a2dd..065879994 100644 --- a/cmake/celix_project/CelixProject.cmake +++ b/cmake/celix_project/CelixProject.cmake @@ -18,7 +18,7 @@ option(ENABLE_ADDRESS_SANITIZER "Enabled building with address sanitizer. Note for gcc libasan must be installed," OFF) option(ENABLE_UNDEFINED_SANITIZER "Enabled building with undefined behavior sanitizer." OFF) option(ENABLE_THREAD_SANITIZER "Enabled building with thread sanitizer." OFF) - +option (ENABLE_GCC_ANALYZER "Enable building with GCC static analyzer." OFF ) # Clear "Advanced" flag for sanitizer options mark_as_advanced(CLEAR ENABLE_ADDRESS_SANITIZER) mark_as_advanced(CLEAR ENABLE_UNDEFINED_SANITIZER) @@ -72,6 +72,15 @@ elseif (ENABLE_THREAD_SANITIZER) set(CMAKE_C_FLAGS "-fsanitize=thread ${CMAKE_C_FLAGS}") set(CMAKE_CXX_FLAGS "-fsanitize=thread ${CMAKE_CXX_FLAGS}") endif() +if (ENABLE_GCC_ANALYZER) + if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_C_FLAGS "-fanalyzer ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-fanalyzer ${CMAKE_CXX_FLAGS}") + else() + message(WARNING "ENABLE_GCC_ANALYZER is only supported with GCC compiler 10.0.0 OR higher.") + endif() +endif() + MACRO(celix_subproject) set(ARGS "${ARGN}") From 0454477abb4f052dbb861223c28c7d3324afc8f1 Mon Sep 17 00:00:00 2001 From: moelksasbyahmed Date: Tue, 27 Jan 2026 14:18:12 +0200 Subject: [PATCH 2/5] added support for gcc -fanalyzer for conanfile --- conanfile.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index bb1c63907..e48c799aa 100644 --- a/conanfile.py +++ b/conanfile.py @@ -94,6 +94,7 @@ class CelixConan(ConanFile): "framework_curlinit": True, "enable_ccache": False, "enable_deprecated_warnings": False, + "enable_gcc_analyzer": False, } options = { "celix_err_buffer_size": ["ANY"], @@ -387,7 +388,10 @@ def generate(self): if "libcurl" in lst: tc.cache_variables["BUILD_ERROR_INJECTOR_CURL"] = "ON" tc.cache_variables["CELIX_ERR_BUFFER_SIZE"] = str(self.options.celix_err_buffer_size) - # tc.cache_variables["CMAKE_PROJECT_Celix_INCLUDE"] = os.path.join(self.build_folder, "conan_paths.cmake") + if self.options.enable_gcc_analyzer and self.settings.compiler == "gcc": + tc.cache_variables["CMAKE_C_FLAGS"] = "-fanalyzer" + tc.cache_variables["CMAKE_CXX_FLAGS"] = "-fanalyzer" + #tc.cache_variables["CMAKE_PROJECT_Celix_INCLUDE"] = os.path.join(self.build_folder, "conan_paths.cmake") # the following is workaround for https://github.com/conan-io/conan/issues/7192 if self.settings.os == "Linux": tc.cache_variables["CMAKE_EXE_LINKER_FLAGS"] = "-Wl,--unresolved-symbols=ignore-in-shared-libs" From 666cf195e8a5c3dca7ba8e9007d999198f4a5dd2 Mon Sep 17 00:00:00 2001 From: moelksasbyahmed Date: Wed, 28 Jan 2026 01:24:01 +0200 Subject: [PATCH 3/5] applied the requested changes --- cmake/celix_project/CelixProject.cmake | 2 +- conanfile.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/cmake/celix_project/CelixProject.cmake b/cmake/celix_project/CelixProject.cmake index 065879994..8135635b2 100644 --- a/cmake/celix_project/CelixProject.cmake +++ b/cmake/celix_project/CelixProject.cmake @@ -77,7 +77,7 @@ if (ENABLE_GCC_ANALYZER) set(CMAKE_C_FLAGS "-fanalyzer ${CMAKE_C_FLAGS}") set(CMAKE_CXX_FLAGS "-fanalyzer ${CMAKE_CXX_FLAGS}") else() - message(WARNING "ENABLE_GCC_ANALYZER is only supported with GCC compiler 10.0.0 OR higher.") + message(WARNING "ENABLE_GCC_ANALYZER is only supported with GCC ") endif() endif() diff --git a/conanfile.py b/conanfile.py index e48c799aa..ab842482a 100644 --- a/conanfile.py +++ b/conanfile.py @@ -94,7 +94,7 @@ class CelixConan(ConanFile): "framework_curlinit": True, "enable_ccache": False, "enable_deprecated_warnings": False, - "enable_gcc_analyzer": False, + } options = { "celix_err_buffer_size": ["ANY"], @@ -388,9 +388,7 @@ def generate(self): if "libcurl" in lst: tc.cache_variables["BUILD_ERROR_INJECTOR_CURL"] = "ON" tc.cache_variables["CELIX_ERR_BUFFER_SIZE"] = str(self.options.celix_err_buffer_size) - if self.options.enable_gcc_analyzer and self.settings.compiler == "gcc": - tc.cache_variables["CMAKE_C_FLAGS"] = "-fanalyzer" - tc.cache_variables["CMAKE_CXX_FLAGS"] = "-fanalyzer" + #tc.cache_variables["CMAKE_PROJECT_Celix_INCLUDE"] = os.path.join(self.build_folder, "conan_paths.cmake") # the following is workaround for https://github.com/conan-io/conan/issues/7192 if self.settings.os == "Linux": From 07c3f503debf8e3bdaf50763ed943d58a1b8e215 Mon Sep 17 00:00:00 2001 From: moelksasbyahmed Date: Wed, 28 Jan 2026 02:54:17 +0200 Subject: [PATCH 4/5] added -fanalyzer flags to suppress warnings in CMake --- cmake/celix_project/CelixProject.cmake | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/cmake/celix_project/CelixProject.cmake b/cmake/celix_project/CelixProject.cmake index 8135635b2..76a74c6bd 100644 --- a/cmake/celix_project/CelixProject.cmake +++ b/cmake/celix_project/CelixProject.cmake @@ -72,10 +72,32 @@ elseif (ENABLE_THREAD_SANITIZER) set(CMAKE_C_FLAGS "-fsanitize=thread ${CMAKE_C_FLAGS}") set(CMAKE_CXX_FLAGS "-fsanitize=thread ${CMAKE_CXX_FLAGS}") endif() + if (ENABLE_GCC_ANALYZER) if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_C_FLAGS "-fanalyzer ${CMAKE_C_FLAGS}") - set(CMAKE_CXX_FLAGS "-fanalyzer ${CMAKE_CXX_FLAGS}") + set(ANALYZER_FLAGS + "-fanalyzer" + "-Wno-analyzer-too-complex" + "-Wno-analyzer-double-fclose" + "-Wno-analyzer-double-free" + "-Wno-analyzer-deref-before-check" + "-Wno-analyzer-exposure-through-output-file" + "-Wno-analyzer-file-leak" + "-Wno-analyzer-free-of-non-heap" + "-Wno-analyzer-malloc-leak" + "-Wno-analyzer-possible-null-argument" + "-Wno-analyzer-possible-null-dereference" + "-Wno-analyzer-null-argument" + "-Wno-analyzer-null-dereference" + "-Wno-analyzer-stale-setjmp-buffer" + "-Wno-analyzer-tainted-array-index" + "-Wno-analyzer-unsafe-call-within-signal-handler" + "-Wno-analyzer-use-after-free" + "-Wno-analyzer-use-of-pointer-in-stale-stack-frame" + "-Wno-analyzer-use-of-uninitialized-value" + "-Wno-analyzer-fd-leak" + ) + add_compile_options(${ANALYZER_FLAGS}) else() message(WARNING "ENABLE_GCC_ANALYZER is only supported with GCC ") endif() From 425b6894f6f4c0d4f94344894014270f5e5c00cc Mon Sep 17 00:00:00 2001 From: moelksasbyahmed Date: Wed, 28 Jan 2026 02:58:07 +0200 Subject: [PATCH 5/5] added gcc analyzer for the ubuntu build --- .github/workflows/ubuntu.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index dc0964f4a..e791de67b 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -155,6 +155,7 @@ jobs: -DCMAKE_BUILD_TYPE=${{ matrix.type }} -DENABLE_CCACHE=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5 + -DENABLE_GCC_ANALYZER=ON -G Ninja run: | mkdir build install