Commit 56f1701c authored by Ben Avison's avatar Ben Avison
Browse files

Suppress cppcheck unusedFunction warnings for CMHG entry points

Just about every C module in the source tree uses CMHG to interface with the
kernel. However, cppcheck doesn't understand CMHG files, and so it will
incorrectly identify any C entry points from the CMHG object file as unused

The main command-line suppression options for cppcheck are:
* --suppress=unusedFunction : blanket suppression of the warning for all
  files. This is undesirable because it would mean we miss many examples of
  dead code, and ironically, since modules commonly feature in ROMs which
  are space-constrained, it's particularly valuable to identify dead code
  in these cases.
* --suppress=unusedFunction:[filename] : better, but a pain to implement the
  CI job for (we'd need to pass it the relevant filename(s) somehow), a pain
  to maintain (for every module, we'd need to identify the relevant file(s))
  and could still miss some dead code.
* --suppress=unusedFunction:[filename]:[line] : solves the dead code problem
  but at the cost of being even more hassle to maintain, due to having to
  keep line numbers up-to-date.

Compared to these options, inline suppression markers look very attractive.
However, objections have been raised to these also, so here we use a new
feature of cppcheck 1.84 (available now that we have upgraded the GitLab
runner machine to Ubuntu 20.04): the more verbose but more flexible option
of passing a suppression specification to cppcheck in XML format. The XML
file itself is generated during the "make standalone" command that is
performed as part of the CI job. For non-module components, the XML file is
not generated, and the option to cppcheck is silently removed.

Required RiscOS/BuildSys!44
parent e61922d2
Pipeline #3920 passed with stage
in 3 seconds
......@@ -586,11 +586,17 @@ BEGIN {
# Extract the C include path and defines directly from the makefile
print " - CFLAGS=$( { cd objs && { echo $'cflags:\\n\\t@echo ${CINCLUDES} ${CDEFINES}'; cat ../Makefile; } | make -f -; } || true )" >> out
# If there's a CMHG file, it will contain the image entry point, so any external dependencies of
# that object file are required even though cppcheck won't be able to identify them by itself.
# The only way to tell cppcheck to suppress unusedFunction warnings by symbol name (rather than
# globally, by file, or file and line number) is to pass it an XML file. We generate suitable XML
# during "make standalone" above, with a standardised filename, so if it exists, use it.
print " - CMHG_XML=$(test -f objs/cmhg-cppcheck-suppress.xml && echo --suppress-xml=objs/cmhg-cppcheck-suppress.xml || true)" >> out
# Enable all warnings except those marked inline, plus shiftNegativeLHS (used in _swix macros and
# therefore ubiquitous) and purgedConfiguration (we don't care if a build switch has no effect).
# cppcheck's --error-exitcode option appears to be too eager to report failure, so synthesise it by
# counting the number of lines printed to stderr.
print " - test ! -d c || { { { { cppcheck --enable=all --suppress=shiftNegativeLHS --suppress=purgedConfiguration --inline-suppr --std=c99 $CFLAGS -UNAMESPACE_OSLIB -U__swi --verbose --max-configs=100 objs/*.c; } 3>&1 1>&2 2>&3; } | tee >( grep -v '^[^ ]* information[:] ' | grep -v '^$' | wc -l >&3 ); } 3>&1 1>&2; } | { read lines; exit $lines; }" >> out
print " - test ! -d c || { { { { cppcheck --enable=all --suppress=shiftNegativeLHS --suppress=purgedConfiguration --inline-suppr $CMHG_XML --std=c99 $CFLAGS -UNAMESPACE_OSLIB -U__swi --verbose --max-configs=100 objs/*.c; } 3>&1 1>&2 2>&3; } | tee >( grep -v '^[^ ]* information[:] ' | grep -v '^$' | wc -l >&3 ); } 3>&1 1>&2; } | { read lines; exit $lines; }" >> out
print " allow_failure: true" >> out
print "" >> out
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment