Skip to content

Commit d6e1044

Browse files
committed
CI: introduce GCC static analysis
Since GCC version 10, there has been a new option -fanalyzer for static analysis. It can make the CI pipeline more comprehensive. Also, the static analysis updates in GCC 11, but we cannot install the GCC 11 in ubuntu 20.04 straightforwardly right now, which is the GitHub workflow environment (see status-check.yaml). For this reason, we stay at the GCC 10. Close #117 Reference - https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Static-Analyzer-Options.html - https://developers.redhat.com/blog/2020/03/26/static-analysis-in-gcc-10 - https://lwn.net/Articles/870290/ - https://developers.redhat.com/blog/2021/01/28/static-analysis-updates-in-gcc-11 - torvalds/linux@7d73c3e
1 parent b0bbe01 commit d6e1044

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

.ci/static-analysis.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,28 @@ function do_sparse()
6060
make -C examples clean
6161
}
6262

63+
function do_gcc()
64+
{
65+
local GCC=$(which gcc-10)
66+
if [ $? -ne 0 ]; then
67+
echo "[!] gcc-10 is not installed. Failed to run static analysis with GCC." >&2
68+
exit 1
69+
fi
70+
71+
make -C examples CONFIG_STATUS_CHECK_GCC=y STATUS_CHECK_GCC=$GCC 2> gcc.log
72+
73+
local WARNING_COUNT=$(cat gcc.log | egrep -c " warning:" )
74+
local ERROR_COUNT=$(cat gcc.log | egrep -c " error:" )
75+
local COUNT=`expr $WARNING_COUNT + $ERROR_COUNT`
76+
if [ $COUNT -gt 0 ]; then
77+
echo "gcc failed: $WARNING_COUNT warning(s), $ERROR_COUNT error(s)"
78+
cat gcc.log
79+
exit 1
80+
fi
81+
make -C examples CONFIG_STATUS_CHECK_GCC=y STATUS_CHECK_GCC=$GCC clean
82+
}
83+
6384
do_cppcheck
6485
do_sparse
86+
do_gcc
6587
exit 0

.github/workflows/status-check.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
run: |
1919
sudo apt-get install -q -y clang-format-11
2020
sudo apt-get install -q -y cppcheck
21+
sudo apt-get install -q -y gcc-10
2122
.ci/check-format.sh
2223
.ci/static-analysis.sh
2324
.ci/build-n-run.sh

examples/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ obj-m += ioctl.o
3232

3333
PWD := $(CURDIR)
3434

35+
ifeq ($(CONFIG_STATUS_CHECK_GCC),y)
36+
CC=$(STATUS_CHECK_GCC)
37+
ccflags-y += -fanalyzer
38+
endif
39+
3540
all:
36-
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
41+
$(MAKE) -C /lib/modules/$(shell uname -r)/build CC=$(CC) M=$(PWD) modules
3742

3843
clean:
39-
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
44+
$(MAKE) -C /lib/modules/$(shell uname -r)/build CC=$(CC) M=$(PWD) clean
4045
$(RM) other/cat_noblock *.plist
4146

4247
indent:

0 commit comments

Comments
 (0)