Enable -Wshift-overflow=2 to check for undefined shift behavior
authorJustin Chadwell <justin.chadwell@arm.com>
Wed, 3 Jul 2019 13:15:56 +0000 (14:15 +0100)
committerJustin Chadwell <justin.chadwell@arm.com>
Fri, 12 Jul 2019 08:12:19 +0000 (09:12 +0100)
The -Wshift-overflow=2 option enables checks for left bit shifts.
Specifically, the option will warn when the result of a shift will be
placed into a signed integer and overflow the sign bit there, which
results in undefined behavior.

To avoid the warnings from these checks, the left operand of a shift can
be made an unsigned integer by using the U() macro or appending the u
suffix.

Change-Id: I50c67bedab86a9fdb6c87cfdc3e784f01a22d560
Signed-off-by: Justin Chadwell <justin.chadwell@arm.com>
Makefile

index 471cf59825e47b2b2c052f8afc212f6bb7f93e0b..c4730929315619c1eafe0bf3413d8a605cdbf460 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -256,9 +256,14 @@ WARNINGS   +=              -Wunused -Wno-unused-parameter  \
                                -Wvla
 
 ifeq ($(findstring clang,$(notdir $(CC))),)
+# not using clang
 WARNINGS       +=              -Wunused-but-set-variable       \
                                -Wmaybe-uninitialized           \
-                               -Wpacked-bitfield-compat
+                               -Wpacked-bitfield-compat        \
+                               -Wshift-overflow=2
+else
+# using clang
+WARNINGS       +=              -Wshift-overflow -Wshift-sign-overflow
 endif
 
 ifneq (${E},0)