Add support of GCC Static Analyzer

It seems to report only false positive.
This commit is contained in:
Patrick Pelissier committed 2021-08-07 17:07:38 +02:00
1 parent 6e6754f84e
commit 05f1cd784c
1 file changed
+16 -2
+16 -2
View File
@@ -44,7 +44,7 @@ all:
.POSIX: .POSIX:
.PHONY: scan-build sanitize check clean *.log coverage synthesis .PHONY: scan-build sanitize check clean *.log coverage synthesis
.SUFFIXES: .SUFFIXES:
.SUFFIXES: .c .exe .log .depend .gcov .SUFFIXES: .c .exe .log .depend .gcov .analyzer
.SECONDARY: .SECONDARY:
.c.exe: .c.exe:
@@ -92,7 +92,7 @@ check: depend
clean: clean:
$(RM) *.exe *.s *~ *.o *.log a*.dat $(RM) *.exe *.s *~ *.o *.log a*.dat
$(RM) *.gcda *.gcno *.gcov all.info test.tar *.synt clang_output_* *.c.c *.end.c *.first.c *.middle.c $(RM) *.gcda *.gcno *.gcov all.info test.tar *.synt clang_output_* *.c.c *.end.c *.first.c *.middle.c *.analyzer
$(RMDIR) coverage coverage-dir mlib-report $(RMDIR) coverage coverage-dir mlib-report
distclean: clean distclean: clean
@@ -195,6 +195,7 @@ synthesis:
# Code analyzer tools # Code analyzer tools
##################################################################################################### #####################################################################################################
# Need clang scan-build
scan-build: clean scan-build: clean
$(RM) -rf ./mlib-report $(RM) -rf ./mlib-report
scan-build -o ./mlib-report $(MAKE) exe XCFLAGS="-std=c99" scan-build -o ./mlib-report $(MAKE) exe XCFLAGS="-std=c99"
@@ -204,6 +205,19 @@ sanitize:
$(MAKE) clean check XCFLAGS="-fsanitize=thread -pie -fPIE" $(MAKE) clean check XCFLAGS="-fsanitize=thread -pie -fPIE"
.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
cat $<.first.c $<.middle.c $<.end.c > $<.c
$(CC) $(CPPFLAGS) $(LDFLAGS) -fanalyzer -Wall -W -O2 -g $<.c -o $<.exe 2> `basename $< .c`.analyzer
$(RM) $<.first.c $<.end.c $<.middle.c $<.c $<.exe
# Need GCC >= 10
analyze:
$(MAKE) `ls test-*.c|$(SED) 's/\.c/\.analyzer/g'`
##################################################################################################### #####################################################################################################
# Test All # Test All
##################################################################################################### #####################################################################################################