From 2c8158241979bedf11c450a5173b680743a17915 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 29 Apr 2024 22:35:27 +0200 Subject: [PATCH] Improve static analyzer report --- tests/Makefile | 4 ++-- tests/coverage.h | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 9fbab0fe..cb544cc6 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -254,9 +254,9 @@ sanitize: .c.analyzer: awk '/START_COVERAGE/ { printit=1} (printit == 0) { print }' $< > $<.first.c awk ' printit { print } /END_COVERAGE/ { printit=1}' $< > $<.end.c - $(CC) $(CPPFLAGS) -E -DNDEBUG -DWITHIN_COVERAGE $< |grep -v '^#' |awk ' /END_COVERAGE/ { printit=0} printit { print } /START_COVERAGE/ { printit=1 }' |perl -p -e "s/;(?![\"'])/;\n/g ; s/}(?![\"'])/}\n/g ; s/{(?![\"'])/{\n/g" > $<.middle.c + $(CC) $(CPPFLAGS) -E -DWITHIN_ANALYZER $< |grep -v '^#' |awk ' /END_COVERAGE/ { printit=0} printit { print } /START_COVERAGE/ { printit=1 }' |perl -p -e "s/;(?![\"'])/;\n/g ; s/}(?![\"'])/}\n/g ; s/{(?![\"'])/{\n/g" > $<.middle.c cat $<.first.c $<.middle.c $<.end.c > $<.c - $(CC) $(CPPFLAGS) -fanalyzer -Wall -W -Wno-analyzer-malloc-leak -O2 -g $<.c -o $<.exe 2> `basename $< .c`.analyzer $(LDFLAGS) + $(CC) $(CPPFLAGS) -fanalyzer -Wall -W -Wno-analyzer-malloc-leak -Wno-stringop-truncation -O2 -g $<.c -o $<.exe 2> `basename $< .c`.analyzer $(LDFLAGS) $(RM) $<.first.c $<.end.c $<.middle.c $<.c $<.exe analyze: diff --git a/tests/coverage.h b/tests/coverage.h index e178117e..b7162a86 100644 --- a/tests/coverage.h +++ b/tests/coverage.h @@ -160,6 +160,28 @@ static void assert(int cond) { if (!cond) abort(); } +#elif defined(WITHIN_ANALYZER) +/* For analyzer build, do not expand other likes NULL, etc. */ +#undef assert +#undef M_STATIC_FAILURE +#undef NULL +#undef M_LIKELY +#undef M_UNLIKELY +#undef M_MEMORY_FULL +#undef M_SWAP +#undef NDEBUG +#undef atomic_init +#undef atomic_load +#undef atomic_store +#undef atomic_compare_exchange_weak +#undef atomic_compare_exchange_strong +#undef atomic_fetch_add +#undef atomic_fetch_sub +#undef M_CONST_CAST +#undef M_ASSIGN_CAST +#undef M_CHECK_DEFAULT_TYPE +#undef M_CHECK_SAME +#undef isspace #else /* For normal builds, empty macros which does nothing */ #define START_COVERAGE