AN-ISC-8-1184_Compiler_Warningss
Compiler Warnings
Version 1.0
2015-11-02
Application Note AN-ISC-8-1184
Author Andreas Raisch
Restrictions Customer confidential – Vector decides
Abstract Warning free code is an important quality goal for embedded software. Nevertheless,
compiler warnings can occur for highly configurable software. Typical compiler
warnings are listed and justified within this document.
Table of Contents 1 Overview ........................................................................................................................................ 2
1.1 Deviation Procedure ............................................................................................................ 3 1.2 Default BSW Delivery Process ............................................................................................ 3 2 Accepted Deviations ..................................................................................................................... 3
2.1 Unused/unreferenced parameter/argument ......................................................................... 4 2.2 Unused/unreferenced define, enum value ........................................................................... 4 2.3 Unused/unreferenced variable ............................................................................................. 4 2.4 Unused/unreferenced function ............................................................................................. 5 2.5 Condition evaluates always to true/false ............................................................................. 5 2.6 Unreachable code/statement ............................................................................................... 6 2.7 Dead assignment / variable set but not used ....................................................................... 6 2.8 ASM statements used .......................................................................................................... 6 3 Additional Resources ................................................................................................................... 7 4 Contacts ......................................................................................................................................... 8

Compiler Warnings
1 Overview MICROSAR BasicSoftware (BSW) is developed in a product line approach, independent from specific
ECU projects or compilers. MICROSAR BSW supports the AUTOSAR MemoryAbstraction and
CompilerAbstraction concepts and supports a huge range of different compiler vendors, versions and
options.
MICROSAR BSW is delivered as static source code and code generators to support the ECU project
specific adaption and optimization of the BSW behavior and feature set based on AUTOSAR
configuration files and user defined selections.
Additionally, MICROSAR BSW supports compile time configuration, link time configuration and post-
build configuration.
Figure 1 MICROSAR BSW Component
A general quality goal for MICROSAR BSW is “warning free code”. The coding style guide for
MICROSAR BSW is based on MISRA-C:2004. Checks for MISRA compliance are an essential part of
our development process. Based on “HIS Gemeinsames Subset der MISRA C Guidelines v2.0“
(http://www.automotive-his.de) all rules are active.
Nevertheless, we accept deviations to the “warning free code” goal based on the here defined list of
exceptions. Known and accepted deviations are reported within the delivery as ESCAN type “Warning
in released product”.
Document [2] explains the relationship between user-selected code generation (optimization) options
and compiler warnings.
Copyright © 2015 - Vector Informatik GmbH
2
Contact Information: www.vector.com or +49-711-80 670-0

Compiler Warnings
1.1 Deviation Procedure Priority Rule Rationale MICROSAR BSW shall be compiler
Detection of compiler warning either during
warning free. Thus, compiler warnings
component development or more frequently
1
shall be prevented wherever possible.
when applying the customer specific
compiler/options/BSW configuration during
the delivery tests.
If a compiler warning is detected, the code We want to prevent to deliver defect code to
shall be analyzed and, if reasonable, be
our customers. We also need to take into
2
changed/extended to become warning
account e.g. runtime efficiency, maintainability
free.
and standardized code for many use-cases.
If fixing the compiler warning is not a
See list of accepted deviations in this
solution, an ESCAN of type “Warning in
document.
3
released product” shall be created to
document the accepted deviation also in
the report of known issues of deliveries.
Table 1 Priority of measures to prevent compiler warnings
1.2 Default BSW Delivery Process The configuration and compilation and linkage during the delivery test activities yield most of the
compiler warnings, because the development tool chain and settings specified by you are used.
The process in short is:
> Customer specifies the compiler brand, version and options (via Questionnaire) and provides
more information on the expected use-case
> Delivery engineer creates example configurations of the BSW and compiles and links the outcome
> Compiler warnings are analyzed and either documented as ESCAN of type “Warning in released
product” or reported to the development teams to trigger a fix.
> ESCANs of type “Issue in released product” and “Warning in released product” are reported within
the delivery documentation as “known issues”
2 Accepted Deviations Deviations in this chapter are typically accepted as “Warning in released product” when
> it has been checked that no incorrect behavior at ECU runtime occurs
> no simple remedy exists
Information
If a compiler warning has passed the analyzing steps according
Table 1 Priority of measures to prevent compiler warnings and the result is still “accepted deviation”, the
compiler warning will not be fixed in the product.
Copyright © 2015 - Vector Informatik GmbH
3
Contact Information: www.vector.com or +49-711-80 670-0
Compiler Warnings
2.1 Unused/unreferenced parameter/argument Deviation ID CW_001
Example compiler „Unreferenced formal parameters“, „parameter is never used“, „has no-used
warning strings argument“
BSW provides APIs as described by standards. Not all parameters are
Reason necessary and used within the function in all possible usage scenarios.
Configuration Yes
dependent Potential risk The function contains unused code.
Code inspection has to check that the unused code is not critical concerning
Prevention of risk the expected behavior. Small increase of ROM footprint is accepted.
Workarounds for suppressing such compiler warnings often conflict with
Note MISRA-C:2004, rule 14.2 (See MISRA Compliance Documentation, Deviation
ID MD_MSR_14.2)
Table 2 CW_001
2.2 Unused/unreferenced define, enum value Deviation ID CW_002
Example compiler „Unused enumeration values“, „Unused define value“
warning strings Encapsulation of defines, enum-values and similar items for multiple complex
Reason configuration data sets (via #ifdef) reduces readability and maintainability.
Configuration Yes
dependent Defined but never used enums or defines may decrease readability and
Potential risk maintainability.
Prevention of risk Execution of runtime tests with different configuration variants.
Note -
Table 3 CW_002
2.3 Unused/unreferenced variable Deviation ID CW_003
„unreferenced local variable within abc.c“, „variable "abc" was declared but
Example compiler never referenced“, „Variables related to message supervision are set but
warning strings never used“
Because of goal "minimize RAM footprint", unused variables shall be disabled
via #ifdef based on configuration data sets.
Reason Nevertheless, warning can occur for rare cases where encapsulation for
multiple complex configuration data sets (via #ifdef) reduces readability and
maintainability.
Configuration Yes
dependent Potential risk The function contains unused code.
Code inspection has to check that the unused variable is not critical
Prevention of risk concerning the expected behavior. Small increase of RAM footprint is
accepted.
Note -
Table 4 CW_003
Copyright © 2015 - Vector Informatik GmbH
4
Contact Information: www.vector.com or +49-711-80 670-0
Compiler Warnings
2.4 Unused/unreferenced function Deviation ID CW_004
Example compiler „Declared but unused function abc“, „unused static function abc“
warning strings BSW provides APIs as described by standard.
Because of goal "minimize ROM footprint", unused functions shall be
disabled via #ifdef based on configuration data sets.
Reason Not all provided functions might be used in the concrete ECU project
(configuration and usage dependent). Encapsulation for multiple complex
configuration data sets (via #ifdef) reduces readability and maintainability and
is thus not provided on a per-function base for all APIs.
Configuration Yes
dependent Potential risk The project contains unused code.
Prevention of risk See “Reason”
Partly addressed by MISRA-C:2004, rule 8.10 (See MISRA Compliance
Note Documentation, Deviation ID MD_MSR_8.10)
Table 5 CW_004
2.5 Condition evaluates always to true/false Deviation ID CW_005
„conditional expression is constant“, „conditional expression or part of it is
Example compiler always true/false / statement not reached“, „condition is always true/false“,
warning strings „compare out of range / condition is always true/false“, „The result of this
logical operation is always 'false' or ‘true’“
Typically caused by an if-statement applied on external configuration data.
Reason Configuration data is const for the given compilation context but might be
changed at link-time or post-build time.
Configuration Yes
dependent Potential risk The function contains useless conditions with possibly dead code.
The code inspection is in charge to distinguish between useless conditions
Prevention of risk with possibly dead code and correct code as described in “reason”.
Note -
Table 6 CW_005
Copyright © 2015 - Vector Informatik GmbH
5
Contact Information: www.vector.com or +49-711-80 670-0
Compiler Warnings
2.6 Unreachable code/statement Deviation ID CW_006
„conditional expression or part of it is always true/false / statement not
Example compiler reached“, „statement will never be executed“, „this switch default label is
warning strings unreachable“
Because of goal "minimize ROM footprint", unreachable code shall be
disabled via #ifdef based on configuration data sets.
Reason Nevertheless, warning might occur as secondary effect on e.g. "condition
evaluates to true/false"
Configuration Yes
dependent Potential risk The function contains unused code.
Code inspection has to check that the unused code is not critical concerning
Prevention of risk the expected behavior. Small increase of ROM footprint is accepted.
Addressed by MISRA-C:2004, rule 14.1 (See MISRA Compliance
Note Documentation, Deviation ID MD_MSR_14.1)
Table 7 CW_006
2.7 Dead assignment / variable set but not used Deviation ID CW_007
“Variable 'abc' was set but never used“, „"local variable is initialized but not
Example compiler referenced", „dead assignment to "abc" eliminated“, „Dead assignment
warning strings (subtraction with zero)“, „Removed dead assignment“
Variable shall be always assigned a valid value. Overwriting the value before
Reason use can therefore happen based on the assumed execution path.
Configuration Yes
dependent Potential risk The function contains unused code and variables.
Code inspection has to check that the unused code is not critical concerning
Prevention of risk the expected behavior. Small increase of ROM/RAM footprint is accepted.
Note -
Table 8 CW_007
2.8 ASM statements used Deviation ID CW_008
Example compiler “asm statements used“
warning strings MICROSAR is written in C but might use compiler specific ASM statements in
Reason rare cases. Usage of ASM is strictly limited by coding style guide.
Configuration No
dependent Potential risk ASM syntax is compiler and compiler version dependent.
Prevention of risk Component release test and delivery test shows correct behavior.
Note -
Table 9 CW_008
Copyright © 2015 - Vector Informatik GmbH
6
Contact Information: www.vector.com or +49-711-80 670-0
Compiler Warnings
3 Additional Resources No Source Title Version Compliance Documentation MISRA
2.3.0 or later
[1]
-C:2004 /
Vector
MICROSAR
[2]
Vector
Technical Reference MICROSAR ComStackLib
2.0.0 or later
Copyright © 2015 - Vector Informatik GmbH
7
Contact Information: www.vector.com or +49-711-80 670-0
Compiler Warnings
4 Contacts For a full list with all Vector locations and addresses worldwide, please visi
t http://vector.com/contact/. Copyright © 2015 - Vector Informatik GmbH
8
Contact Information: www.vector.com or +49-711-80 670-0