[PATCH 4/8] riscv: ensure RISC-V C model definitions are passed to static analyzers

From: Paul Walmsley
Date: Thu Oct 17 2019 - 20:50:12 EST


Static analysis tools such as sparse don't set the RISC-V C model
preprocessor directives such as "__riscv_cmodel_medany", set by the C
compilers. This causes the static analyzers to evaluate different
preprocessor paths than C compilers would. Fix this by defining the
appropriate C model macros in the static analyzer command lines.

Signed-off-by: Paul Walmsley <paul.walmsley@xxxxxxxxxx>
---
arch/riscv/Makefile | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index f5e914210245..0247a90bd4d8 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -47,9 +47,11 @@ KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)

ifeq ($(CONFIG_CMODEL_MEDLOW),y)
KBUILD_CFLAGS += -mcmodel=medlow
+ CHECKFLAGS += -D__riscv_cmodel_medlow
endif
ifeq ($(CONFIG_CMODEL_MEDANY),y)
KBUILD_CFLAGS += -mcmodel=medany
+ CHECKFLAGS += -D__riscv_cmodel_medany
endif
ifeq ($(CONFIG_MODULE_SECTIONS),y)
KBUILD_LDS_MODULE += $(srctree)/arch/riscv/kernel/module.lds
--
2.23.0