[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [XEN PATCH v2 1/2] automation/eclair: update configuration of Rule 20.7
On Tue, 10 Sep 2024, Federico Serafini wrote: > MISRA C:2012 Rule 20.7 states that "Expressions resulting from the > expansion of macro parameters shall be enclosed in parentheses". > The rational of the rule is that if a macro argument expands to an > expression, there may be problems related to operator precedence, e.g., > > define M(A, B) A * B > > M(1+1, 2+2) will expand to: 1+1 * 2+2 > > Update ECLAIR configuration to tag as 'safe' the expansions of macro > arguments surrounded tokens '{', '}' and ';', since in their presence > problems related to operator precedence can not occur. > > Signed-off-by: Federico Serafini <federico.serafini@xxxxxxxxxxx> Acked-by: Stefano Stabellini <sstabellini@xxxxxxxxxx> > --- > Changes from v1: > - more details to justify the deviation; > - split modifications in two patches. > --- > automation/eclair_analysis/ECLAIR/deviations.ecl | 4 ++++ > docs/misra/deviations.rst | 5 +++++ > 2 files changed, 9 insertions(+) > > diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl > b/automation/eclair_analysis/ECLAIR/deviations.ecl > index 9051f41602..e0d9426b7a 100644 > --- a/automation/eclair_analysis/ECLAIR/deviations.ecl > +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl > @@ -581,6 +581,10 @@ of this macro do not lead to developer confusion, and > can thus be deviated." > -config=MC3R1.R20.7,reports+={safe, > "any_area(any_loc(any_exp(macro(^count_args_$))))"} > -doc_end > > +-doc_begin="Problems related to operator precedence can not occur if the > expansion of the macro argument is surrounded by tokens '{', '}' and ';'." > +-config=MC3R1.R20.7,expansion_context+={safe, > "left_right(^[\\{;]$,^[;\\}]$)"} > +-doc_end > + > -doc_begin="Uses of variadic macros that have one of their arguments defined > as > a macro and used within the body for both ordinary parameter expansion and > as an > operand to the # or ## operators have a behavior that is well-understood and > diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst > index b66c271c4e..69f93a6a91 100644 > --- a/docs/misra/deviations.rst > +++ b/docs/misra/deviations.rst > @@ -534,6 +534,11 @@ Deviations related to MISRA C:2012 Rules: > refactoring it to add parentheses breaks its functionality. > - Tagged as `safe` for ECLAIR. > > + * - R20.7 > + - Problems related to operator precedence can not occur if the expansion > + of the macro argument is surrounded by tokens '{', '}' and ';'. > + - Tagged as `safe` for ECLAIR. > + > * - R20.12 > - Variadic macros that use token pasting often employ the gcc extension > `ext_paste_comma`, as detailed in `C-language-toolchain.rst`, which is > -- > 2.34.1 >
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |