diff --git a/Makefile.base b/Makefile.base index 95ad434773..b9feb37f40 100644 --- a/Makefile.base +++ b/Makefile.base @@ -78,6 +78,14 @@ ifneq (,$(SRCXX)) endif endif +# If static analysis is enabled *and* the module claims to compile fine with it, +# add the corresponding flags +ifeq (1,$(STATIC_ANALYSIS)) + ifeq (1,$(MODULE_SUPPORTS_STATIC_ANALYSIS)) + CFLAGS := $(CFLAGS_STATIC_ANALYSIS) $(CFLAGS) + endif +endif + compile-commands: | $(DIRS:%=COMPILE-COMMANDS--%) $(file >$(BINDIR)/$(MODULE)/compile_cmds.txt,SRC: $(sort $(SRC) $(SRC_NO_LTO))) $(file >>$(BINDIR)/$(MODULE)/compile_cmds.txt,SRC_NO_LTO: $(sort $(SRC_NO_LTO))) diff --git a/core/Makefile b/core/Makefile index e03d095c13..2ce4fb9f02 100644 --- a/core/Makefile +++ b/core/Makefile @@ -4,4 +4,7 @@ SRC := $(filter-out mbox.c msg.c msg_bus.c thread.c thread_flags.c,$(wildcard *. # enable submodules SUBMODULES := 1 +# this module is expected to pass static analysis +MODULE_SUPPORTS_STATIC_ANALYSIS := 1 + include $(RIOTBASE)/Makefile.base diff --git a/makefiles/toolchain/gnu.inc.mk b/makefiles/toolchain/gnu.inc.mk index 20245c2756..baaed88d0d 100644 --- a/makefiles/toolchain/gnu.inc.mk +++ b/makefiles/toolchain/gnu.inc.mk @@ -36,6 +36,9 @@ OPTIONAL_CFLAGS_BLACKLIST += -Wdocumentation -Wno-error=documentation -Wno-docum # We use GDB for debugging include $(RIOTMAKE)/tools/gdb.inc.mk +# GCC's static analysis tools can be enabled using -fanalyzer +CFLAGS_STATIC_ANALYSIS := -fanalyzer + # Data address spaces starts at zero for all supported architectures. This fixes # compilation at least on MSP430 and AVR. # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 diff --git a/makefiles/vars.inc.mk b/makefiles/vars.inc.mk index d595f15a72..1e01c83e06 100644 --- a/makefiles/vars.inc.mk +++ b/makefiles/vars.inc.mk @@ -70,6 +70,7 @@ export CXX # The CXX compiler to use. export CCAS # The C compiler to use for assembler files, typically the same as CC. export CFLAGS # The compiler flags. Must only ever be used with `+=`. export CFLAGS_CPU # CPU architecture specific compiler flags +export CFLAGS_STATIC_ANALYSIS# Additional CFLAGS to use when static analysis should be enabled export CXXUWFLAGS # (Patterns of) flags in CFLAGS that should not be passed to CXX. export CXXEXFLAGS # Additional flags that should be passed to CXX. export CCASUWFLAGS # (Patterns of) flags in CFLAGS that should not be passed to CCAS.