Skip to content

Commit bd27851

Browse files
LoveKarlssonkartben
authored andcommitted
cmake: Fix warning levels for IAR
Rewrote the warning levels for toolchain IAR as IAR tools just turn off warnings, not on. Also did some minor cleanup for coding guidelines. Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
1 parent a5d023a commit bd27851

File tree

2 files changed

+60
-50
lines changed

2 files changed

+60
-50
lines changed

cmake/compiler/iar/compiler_flags.cmake

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,60 @@ set_compiler_property(PROPERTY optimization_fast --no_size_constraints)
2323
# This section covers flags related to warning levels #
2424
#######################################################
2525

26-
# Property for standard warning base in Zephyr, this will always be set when
27-
# compiling.
28-
set_compiler_property(PROPERTY warning_base
29-
--diag_error=Pe223 # function "xxx" declared implicitly
30-
--diag_warning=Pe054 # too few arguments in invocation of macro
31-
--diag_warning=Pe144 # a value of type "void *" cannot be used to initialize an entity of type [...] "void (*)(struct onoff_manager *, int)"
32-
--diag_warning=Pe167 # argument of type "void *" is incompatible with [...] "void (*)(void *, void *, void *)"
33-
--diag_suppress=Pe1675 # unrecognized GCC pragma
34-
--diag_suppress=Pe111 # statement is unreachable
35-
--diag_suppress=Pe1143 # arithmetic on pointer to void or function type
36-
--diag_suppress=Pe068) # integer conversion resulted in a change of sign)
37-
38-
39-
set(IAR_WARNING_DW_1
40-
--diag_suppress=Pe188 # enumerated type mixed with another type
41-
--diag_suppress=Pe128 # loop is not reachable
42-
--diag_suppress=Pe550 # variable "res" was set but never used
43-
--diag_suppress=Pe546 # transfer of control bypasses initialization
44-
--diag_suppress=Pe186) # pointless comparison of unsigned integer with zero
45-
46-
set(IAR_WARNING_DW2
47-
--diag_suppress=Pe1097 # unknown attribute
48-
--diag_suppress=Pe381 # extra ";" ignored
49-
--diag_suppress=Pa082 # undefined behavior: the order of volatile accesses is undefined
50-
--diag_suppress=Pa084 # pointless integer comparison, the result is always false
51-
--diag_suppress=Pe185 # dynamic initialization in unreachable code )
52-
--diag_suppress=Pe167 # argument of type "onoff_notify_fn" is incompatible with...
53-
--diag_suppress=Pe144 # a value of type "void *" cannot be used to initialize...
54-
--diag_suppress=Pe177 # function "xxx" was declared but never referenced
55-
--diag_suppress=Pe513) # a value of type "void *" cannot be assigned to an entity of type "int (*)(int)"
56-
57-
set(IAR_WARNING_DW3)
58-
59-
set_compiler_property(PROPERTY warning_dw_1
60-
${IAR_WARNING_DW_3}
61-
${IAR_WARNING_DW_2}
62-
${IAR_WARNING_DW_1})
63-
64-
set_compiler_property(PROPERTY warning_dw_2
65-
${IAR_WARNING_DW3}
66-
${IAR_WARNING_DW2})
67-
68-
# no suppressions
69-
set_compiler_property(PROPERTY warning_dw_3 ${IAR_WARNING_DW3})
26+
# -DW=... settings
27+
#
28+
# W=1 - warnings that may be relevant and does not occur too often
29+
# W=2 - warnings that occur quite often but may still be relevant
30+
# W=3 - the more obscure warnings, can most likely be ignored
31+
32+
set(IAR_SUPPRESSED_WARNINGS)
33+
34+
# Set basic suppressed warning first
35+
36+
# Pe223: function "xxx" declared implicitly
37+
# Pe054: too few arguments in invocation of macro
38+
# Pe1675: unrecognized GCC pragma
39+
# Pe111: statement is unreachable
40+
# Pe1143: arithmetic on pointer to void or function type
41+
# Pe068: integer conversion resulted in a change of sign
42+
list(APPEND IAR_SUPPRESSED_WARNINGS
43+
--diag_suppress=Pe068,Pe1143,Pe111,Pe1675,Pe054,Pe223)
44+
45+
# Since IAR does not turn on warnings we do this backwards
46+
# by not suppressing warnings on higher levels.
47+
if(NOT W MATCHES "3")
48+
# Pe381: extra ";" ignored
49+
list(APPEND IAR_SUPPRESSED_WARNINGS --diag_suppress=Pe381)
50+
endif()
51+
if(NOT W MATCHES "2" AND NOT W MATCHES "3")
52+
# Pe1097: unknown attribute
53+
# Pa082: undefined behavior: the order of volatile accesses is undefined
54+
# Pa084: pointless integer comparison, the result is always false
55+
# Pe185: dynamic initialization in unreachable code
56+
# Pe167: argument of type "onoff_notify_fn" is incompatible with...
57+
# Pe144: a value of type "void *" cannot be used to initialize...
58+
# Pe177: function "xxx" was declared but never referenced
59+
# Pe513: a value of type "void *" cannot be assigned to an
60+
# entity of type "int (*)(int)"
61+
list(APPEND IAR_SUPPRESSED_WARNINGS
62+
--diag_suppress=Pe513,Pe177,Pe144,Pe167,Pe185,Pa084,Pa082,Pe1097)
63+
endif()
64+
if(NOT W MATCHES "1" AND NOT W MATCHES "2" AND NOT W MATCHES "3")
65+
# Pe188: enumerated type mixed with another type
66+
# Pe128: loop is not reachable
67+
# Pe550: variable "res" was set but never used
68+
# Pe546: transfer of control bypasses initialization
69+
# Pe186: pointless comparison of unsigned integer with zero
70+
# Pe054: too few arguments in invocation of macro xxx
71+
# Pe144: a value of type "void *" cannot be used to initialize an
72+
# entity of type [...] "void (*)(struct onoff_manager *, int)"
73+
# Pe167: argument of type "void *" is incompatible with [...]
74+
# "void (*)(void *, void *, void *)"
75+
list(APPEND IAR_SUPPRESSED_WARNINGS
76+
--diag_suppress=Pe054,Pe186,Pe546,Pe550,Pe128,Pe188,Pe144,Pe167)
77+
endif()
78+
79+
set_compiler_property(PROPERTY warning_base ${IAR_SUPPRESSED_WARNINGS})
7080

7181
# Extended warning set supported by the compiler
7282
set_compiler_property(PROPERTY warning_extended)
@@ -77,7 +87,7 @@ set_compiler_property(PROPERTY warning_error_implicit_int)
7787
# Compiler flags to use when compiling according to MISRA
7888
set_compiler_property(PROPERTY warning_error_misra_sane)
7989

80-
set_property(TARGET compiler PROPERTY warnings_as_errors --warnings_are_errors)
90+
set_property(TARGET compiler PROPERTY warnings_as_errors --warnings_are_errors)
8191

8292
###########################################################################
8393
# This section covers flags related to C or C++ standards / standard libs #
@@ -151,7 +161,6 @@ set_compiler_property(PROPERTY freestanding)
151161
# Flag to include debugging symbol in compilation
152162
set_property(TARGET compiler PROPERTY debug --debug)
153163
set_property(TARGET compiler-cpp PROPERTY debug --debug)
154-
set_property(TARGET asm PROPERTY debug -gdwarf-4)
155164

156165
set_compiler_property(PROPERTY no_common)
157166

cmake/compiler/iar/target.cmake

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ if("${IAR_TOOLCHAIN_VARIANT}" STREQUAL "iccarm")
7676
list(APPEND IAR_COMMON_FLAGS
7777
--endian=little
7878
--cpu=${ICCARM_CPU}
79-
-DRTT_USE_ASM=0 #WA for VAAK-232
80-
--diag_suppress=Ta184 # Using zero sized arrays except for as last member of a struct is discouraged and dereferencing elements in such an array has undefined behavior
79+
-DRTT_USE_ASM=0 # WA for VAAK-232
80+
--diag_suppress=Ta184 # Using zero sized arrays except for as last
81+
# member of a struct is discouraged and
82+
# dereferencing elements in such an array has
83+
# undefined behavior
8184
)
8285
endif()
8386

@@ -121,9 +124,7 @@ if("${IAR_TOOLCHAIN_VARIANT}" STREQUAL "iccarm")
121124
list(APPEND IAR_ASM_FLAGS -mfpu=${GCC_M_FPU})
122125
endif()
123126
endif()
124-
endif()
125127

126-
if("${IAR_TOOLCHAIN_VARIANT}" STREQUAL "iccarm")
127128
if(CONFIG_IAR_LIBC)
128129
# Zephyr requires AEABI portability to ensure correct functioning of the C
129130
# library, for example error numbers, errno.h.

0 commit comments

Comments
 (0)