build: include -Wextra in generic builds

TF-A is more strict with compiler warnings in comparison to other
projects (notably Linux) for security and -Wextra enables a lot of
desirable warnings. This patch enables -Wextra by default (from W=1
previously) and reorganises the warning levels so that they can useful
when enabled and not just a build failure. This will help us move
towards fixing the warnings that are too many to fix at once and
enabling all W={1, 2} warnings.

The warning levels get new meanings:
* W=1: warnings we want the generic build to include but are too time
  consuming to fix at the moment. They re-enable warnings taken out for
  generic builds.
* W=2: warnings we want the generic build to include but cannot be
  enabled due to external libraries.
* W=3: warnings that are informative but not necessary and generally too
  verbose and frequently ignored.

Quality expectations for new contributions mean that generally they
should have no warnings up to W=2. To allow code to be developed with
them in mind, -Werror is disabled when W=x is set. This way enabling
warnings will not just fail the build due to technicalities we have and
contributors will be able to actually see if they get any.

Signed-off-by: Boyan Karatotev <boyan.karatotev@arm.com>
Change-Id: Ieb15ddd635d458a956a34b0f9d0ea2f81b9c0745
This commit is contained in:
Boyan Karatotev 2022-11-21 14:16:43 +00:00
parent 228b06a535
commit d75a9ecdaa

View file

@ -350,27 +350,51 @@ ASFLAGS_aarch64 = $(march64-directive)
# General warnings
WARNINGS := -Wall -Wmissing-include-dirs -Wunused \
-Wdisabled-optimization -Wvla -Wshadow \
-Wno-unused-parameter -Wredundant-decls
-Wredundant-decls
# stricter warnings
WARNINGS += -Wextra -Wno-trigraphs
# too verbose for generic build
WARNINGS += -Wno-missing-field-initializers \
-Wno-type-limits -Wno-sign-compare \
# on clang this flag gets reset if -Wextra is set after it. No difference on gcc
WARNINGS += -Wno-unused-parameter
# Additional warnings
# Level 1
WARNING1 := -Wextra
WARNING1 += -Wmissing-format-attribute
WARNING1 += -Wmissing-prototypes
WARNING1 += -Wold-style-definition
# Level 1 - infrequent warnings we should have none of
# full -Wextra
WARNING1 += -Wsign-compare
WARNING1 += -Wtype-limits
WARNING1 += -Wmissing-field-initializers
# Level 2
WARNING2 := -Waggregate-return
WARNING2 += -Wcast-align
WARNING2 += -Wnested-externs
# Level 2 - problematic warnings that we want
# zlib, compiler-rt, coreboot, and mbdedtls blow up with these
# TODO: disable just for them and move into default build
WARNING2 += -Wold-style-definition
WARNING2 += -Wmissing-prototypes
WARNING2 += -Wmissing-format-attribute
# TF-A aims to comply with this eventually. Effort too large at present
WARNING2 += -Wundef
# Level 3 - very pedantic, frequently ignored
WARNING3 := -Wbad-function-cast
WARNING3 += -Waggregate-return
WARNING3 += -Wnested-externs
WARNING3 += -Wcast-align
WARNING3 += -Wcast-qual
WARNING3 += -Wconversion
WARNING3 += -Wpacked
WARNING3 += -Wpointer-arith
WARNING3 += -Wswitch-default
# Setting W is quite verbose and most warnings will be pre-existing issues
# outside of the contributor's control. Don't fail the build on them so warnings
# can be seen and hopefully addressed
ifdef W
ifneq (${W},0)
E ?= 0
endif
endif
ifeq (${W},1)
WARNINGS += $(WARNING1)
else ifeq (${W},2)