Skip to contentSkip to conversation

Xen reliance on non-standard GCC features

DISCUSSION Roberto Bagnara 8 participants 20 messages Jun 5, 2023 – Jun 9, 2023

lore
Share & tools
lore
#0 lore raw

Hi there.

It appears Xen uses lots of GCC features that are outside the C99 standard. Some of them are documented GNU extensions to the language. Some of them seem not to be documented, so they do not qualify as language extensions (at least, not as far as the spirit and letter of functional-safety standards are concerned).

Language extensions come with two problems:

a) They limit portability.
b) They significantly increase the cost of compiler qualification (commercial C compiler validation suites do not cover the extensions, and the cost of the extra validation effort will have to be born by whomever wants to use Xen for safety-related development).

Said that, maybe the use of certain extensions is intentional, but for others it may be unintentional. The purpose of this message is to distinguish the ones from the others. In the following, when I mention the C99 standard, I refer to compiler uses with -std=c99 or -std=gnu99.

Let us start from the (as far as I can tell) undocumented extensions:

U1) Use of _Static_assert in C99 mode.

U2) Empty initialization lists, both in C99 mode (ARM64 and X86_64)

    and C18 mode (only X86_64).

U3) Returning void expressions.

U4) Static functions or variables used in inline functions with external
linkage.

U5) Enumerator values outside the range of `int'.

U6) Empty declarations.

U7) Empty enum definitions.

U8) Conversion between incompatible pointer types.

U9) Conversion between function pointers and object pointers.

U10) \m escape sequence.
Is this an undocumented GCC extension or just a typo?

In case you know where these are documented in the GCC manual, I would appreciate if you could tell me.

Here is a list of extensions that are documented in the GCC manual:

D1) Arithmetic operators on `void *' type:
See Section "6.24 Arithmetic on void- and Function-Pointers" of the GCC manual."

D2) Sizeof and alignof on `void *' type:
See Section "6.24 Arithmetic on void- and Function-Pointers" of the GCC manual."

D3) Use of GNU statement expressions.
See Section "6.1 Statements and Declarations in Expressions" of the GCC manual.

D4) Use of GNU statement expressions from macro expansion.
See Section "6.1 Statements and Declarations in Expressions" of the GCC manual.
(My advice is to read it fully, as there are implications.)

D5) Record declarations with no members.
See Section "6.19 Structures with No Members" of the GCC manual."

D6) Structures containing a flexible array member as member of a structure.
See Section "6.18 Arrays of Length Zero" of the GCC manual.

D7) Structures containing a flexible array member as element of an array.
See Section "6.18 Arrays of Length Zero" of the GCC manual.

D8) Binary conditional operator.
See Section "6.8 Conditionals with Omitted Operands" of the GCC manual.

D9) Case labels with upper/lower values.
See Section "6.30 Case Ranges" of the GCC manual.

D10) Anonymous structure and union fields.
See Section "6.63 Unnamed Structure and Union Fields" of the GCC manual.

D11) Variadic macros called without any argument for '...'
See Section "6.21 Macros with a Variable Number of Arguments" of the GCC manual.

D12) Forward references to enum definitions.
See Section "6.49 Incomplete enum Types" of the GCC manual.

Finally, Xen seems to rely on explicitly undefined behavior, namely
C99 UB 58: "A structure or union is defined as containing no named
members (6.7.2.1)." All instances but one occur via macro BUILD_BUG_ON_ZERO, the remaining instance concerns struct
`cpu_policy::<anonymous union>::<anonymous struct>::<anonymous union>::<anonymous struct>'. Reliance on undefined behavior might be hard to justify.

I look forward to receiving your feedback.
Kind regards,

Roberto

#1 lore raw
Quoted 6 lines · Roberto Bagnara

Finally, Xen seems to rely on explicitly undefined behavior, namely
C99 UB 58: "A structure or union is defined as containing no named
members (6.7.2.1)." All instances but one occur via macro BUILD_BUG_ON_ZERO, the remaining instance concerns struct
`cpu_policy::<anonymous union>::<anonymous struct>::<anonymous union>::<anonymous struct>'. Reliance on undefined behavior might be hard to justify.

For starters just a comment here: I'm pretty sure this case was discussed before, and that it was agreed that if need be we'd simply add _ as the name there. Yet then - how did you notice this? Code inspection? I would expect no analysis tool would spot it because it's used for gcc < 4.6 only. And I doubt you run analysis tools in combination with this old a gcc?

Jan

#2 lore raw
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Roberto Bagnara

Finally, Xen seems to rely on explicitly undefined behavior, namely
C99 UB 58: "A structure or union is defined as containing no named
members (6.7.2.1)." All instances but one occur via macro BUILD_BUG_ON_ZERO, the remaining instance concerns struct
`cpu_policy::<anonymous union>::<anonymous struct>::<anonymous union>::<anonymous struct>'. Reliance on undefined behavior might be hard to justify.

Quoted 6 lines

For starters just a comment here: I'm pretty sure this case was discussed before, and that it was agreed that if need be we'd simply add _ as the name there. Yet then - how did you notice this? Code inspection? I would expect no analysis tool would spot it because it's used for gcc < 4.6 only. And I doubt you run analysis tools in combination with this old a gcc?

It is detected by ECLAIR, but the analysis is based on GCC 12, and the detection of implementation-defined behaviors (including predefined macros) is completely automatic, so I don't think there is any configuration error.

One of the instances arises from

xen/arch/arm/dm.c:50.19-50.37:
all the members of struct `dm_op(const struct dmop_args*)::<anonymous struct>' are unnamed (undefined for the C99 standard, ISO/IEC 9899:1999 Annex J.2 item 58: "A structure or union is defined as containing no named members (6.7.2.1)." [STD.anonstct]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

and, in turn:

xen/include/xen/lib.h:54.12-54.17: expanded from macro BUILD_BUG_ON_ZERO' xen/include/xen/compiler.h:126.3-126.77: expanded from macro __must_be_array' xen/include/xen/lib.h:77.53-77.70: expanded from macro `ARRAY_SIZE'

I apologize in advance if I have misunderstood something. Kind regards,

Roberto

#3 lore raw
Quoted 21 lines · Roberto Bagnara
Quoted 8 lines · Jan Beulich
Quoted 6 lines · Roberto Bagnara

Finally, Xen seems to rely on explicitly undefined behavior, namely
C99 UB 58: "A structure or union is defined as containing no named
members (6.7.2.1)." All instances but one occur via macro BUILD_BUG_ON_ZERO, the remaining instance concerns struct
`cpu_policy::<anonymous union>::<anonymous struct>::<anonymous union>::<anonymous struct>'. Reliance on undefined behavior might be hard to justify.

Quoted 6 lines

For starters just a comment here: I'm pretty sure this case was discussed before, and that it was agreed that if need be we'd simply add _ as the name there. Yet then - how did you notice this? Code inspection? I would expect no analysis tool would spot it because it's used for gcc < 4.6 only. And I doubt you run analysis tools in combination with this old a gcc?

It is detected by ECLAIR, but the analysis is based on GCC 12, and the detection of implementation-defined behaviors (including predefined macros) is completely automatic, so I don't think there is any configuration error.

Quoted 8 lines

One of the instances arises from

xen/arch/arm/dm.c:50.19-50.37:
all the members of struct `dm_op(const struct dmop_args*)::<anonymous struct>' are unnamed (undefined for the C99 standard, ISO/IEC 9899:1999 Annex J.2 item 58: "A structure or union is defined as containing no named members (6.7.2.1)." [STD.anonstct]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

and, in turn:

xen/include/xen/lib.h:54.12-54.17: expanded from macro `BUILD_BUG_ON_ZERO'

Oh, indeed:

#define BUILD_BUG_ON_ZERO(cond) \
    sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); })

uses a struct with no real member as well. I did overlook this earlier on. Not sure though how to deal with this here.

Jan

Quoted 7 lines

xen/include/xen/compiler.h:126.3-126.77: expanded from macro __must_be_array' xen/include/xen/lib.h:77.53-77.70: expanded from macro ARRAY_SIZE'

I apologize in advance if I have misunderstood something. Kind regards,

Roberto

#4 lore raw
In reply to Roberto Bagnara
Quoted 2 lines · Roberto Bagnara

U10) \m escape sequence.
     Is this an undocumented GCC extension or just a typo?

Where are you seeing this?

The only examples I see are in asm macros, and they're all parameter substitutions.

This includes the one in x86's bug.h where it's a parameter substitution into an .ascii string literal, not an escaped special character in the literal.

~Andrew

#5 lore raw
Quoted 4 lines · Andrew Cooper
Quoted 2 lines · Roberto Bagnara

U10) \m escape sequence.
     Is this an undocumented GCC extension or just a typo?

Quoted 8 lines

Where are you seeing this?

The only examples I see are in asm macros, and they're all parameter substitutions.

This includes the one in x86's bug.h where it's a parameter substitution into an .ascii string literal, not an escaped special character in the literal.

The point is that escape sequences must be considered for tokenization, which happens in translation phase 3, as they are relevant for phase 4, which is where preprocessing directives are processed and removed.

See C99 Section "5.1.1.2 Translation phases" for the definition of the phases. So \m is non-compliant even in areas guarded by

#if defined(__ASSEMBLY__)

and a conforming compiler should flag it. On this, see footnote 65 to 6.4.4.4p8, where the 'm' in '\m' is one of "any other character":

65) The semantics of these characters were discussed in 5.2.2.
If any other character follows a backslash, the result is not a token and a diagnostic is required. See ‘‘future language directions’’ (6.11.4).

Kind regards,

Roberto

P.S. Note on passing that the comments on the preprocessing directives
are a bit misleading due to the use of the exclamation mark (IMHO "defined(__ASSEMBLY__)" would be better than "!__ASSEMBLY__"):

#ifndef __ASSEMBLY__

...

#else /* !__ASSEMBLY__ */

...

#endif /* !__ASSEMBLY__ */

#6 lore raw
Quoted 10 lines · Roberto Bagnara
Quoted 9 lines · Andrew Cooper
Quoted 2 lines · Roberto Bagnara

U10) \m escape sequence.
     Is this an undocumented GCC extension or just a typo?

Where are you seeing this?

The only examples I see are in asm macros, and they're all parameter substitutions.

Quoted 7 lines
Quoted 3 lines

This includes the one in x86's bug.h where it's a parameter substitution into an .ascii string literal, not an escaped special character in the literal.

The point is that escape sequences must be considered for tokenization, which happens in translation phase 3, as they are relevant for phase 4, which is where preprocessing directives are processed and removed.

The C99 text mentions escape sequences the first time in phase 5, which means string literals inside preprocessor conditionals which evaluated to false were already removed. For tokenization all that should matter is escaped double quotes (when determining the end of a string literal), escaped single quotes (when processing character constants), and escaped backslashes.

Quoted 22 lines

See C99 Section "5.1.1.2 Translation phases" for the definition of the phases. So \m is non-compliant even in areas guarded by

#if defined(__ASSEMBLY__)

and a conforming compiler should flag it. On this, see footnote 65 to 6.4.4.4p8, where the 'm' in '\m' is one of "any other character":

65) The semantics of these characters were discussed in 5.2.2.
If any other character follows a backslash, the result is not a token and a diagnostic is required. See ‘‘future language directions’’ (6.11.4).

Kind regards,

Roberto

P.S. Note on passing that the comments on the preprocessing directives
are a bit misleading due to the use of the exclamation mark (IMHO "defined(__ASSEMBLY__)" would be better than "!__ASSEMBLY__"):

#ifndef __ASSEMBLY__

Quoted 7 lines

...

#else /* !__ASSEMBLY__ */

...

#endif /* !__ASSEMBLY__ */

As long as these comments are unambiguous, I for one strictly prefer the shorter form.

Jan

#7 lore raw
In reply to Roberto Bagnara
Quoted 9 lines · Roberto Bagnara

It appears Xen uses lots of GCC features that are outside the C99 standard. Some of them are documented GNU extensions to the language. Some of them seem not to be documented, so they do not qualify as language extensions (at least, not as far as the spirit and letter of functional-safety standards are concerned).

Language extensions come with two problems:

a) They limit portability.

Sure, it was (I think) always clear that by using extensions we limit what other compilers Xen may be possible to be built with.

Quoted 11 lines

b) They significantly increase the cost of compiler qualification (commercial C compiler validation suites do not cover the extensions, and the cost of the extra validation effort will have to be born by whomever wants to use Xen for safety-related development).

Said that, maybe the use of certain extensions is intentional, but for others it may be unintentional. The purpose of this message is to distinguish the ones from the others. In the following, when I mention the C99 standard, I refer to compiler uses with -std=c99 or -std=gnu99.

Let us start from the (as far as I can tell) undocumented extensions:

I'd like to mention that many "smaller" extensions are either not mentioned anywhere, or are part of "bigger" extension doc. See e.g. near the end of 6.20 "Arrays of Variable Length" (gcc 13.1.0 doc), explaining parameter forward declarations as "another GNU extension". (Sadly that pattern doesn't have further matches when searching for it.)

Quoted 6 lines

U1) Use of _Static_assert in C99 mode.

U2) Empty initialization lists, both in C99 mode (ARM64 and X86_64)

     and C18 mode (only X86_64).

U3) Returning void expressions.

As per above, tiny extensions like these are, I think, unlikely to be mentioned anywhere explicitly (or more than in passing). For the last of the three it may further be that it pre-dates when gcc started to properly document extensions. Oh, actually - U3 is documented along with -Wreturn-type.

Uses are generally intentional afaik, but eliminating cases of U2 and U3 would likely be possible with just slight overall impact.

As to U2, it's not clear why you distinguish C99 and C18 mode. Throughout this summary of yours it would likely have been helpful if an example was provided for the behavior your describing, when the wording doesn't make it crystal clear (e.g. no example needed for U1 and U3 above).

As to U1, I'm afraid this statement very early in gcc's section documenting C extensions simply hasn't been properly updated for newer versions of the standard: "Some features that are in ISO C99 but not C90 or C++ are also, as extensions, accepted by GCC in C90 mode and in C++." A somewhat similar statement in the middle of 2.1 "C Language" is slightly better, thus covering at least the specific case of _Static_assert.

Quoted 2 lines

U4) Static functions or variables used in inline functions with external
linkage.

There's not a lot of "extern inline" that we've accumulated so far, I think. The only ones I'm aware of are sort() and bsearch(), and there the use is precisely for allowing the compiler to optimize away function calls.

The documentation of this functionality is that of the gnu_inline function attribute, afaict. That would be 6.33.1 "Common Function Attributes" in 13.1.0 doc.

Quoted 3 lines

U5) Enumerator values outside the range of `int'.

U6) Empty declarations.

For these two I'm surprised you say we have any. The former would need inspecting, but it's hard to see why the latter shouldn't simply allow purging. Provided I understand correctly why you mean by "empty", not the least because ...

Quoted 1 line

U7) Empty enum definitions.

... here I wonder whether instead you mean forward declaration of enums (i.e. what the standard allows for structures and unions only).

Quoted 1 line

U8) Conversion between incompatible pointer types.

Do we have any uses that aren't, by using casts, documenting that the conversions are deliberate? Otherwise I would expect the compiler to warn, and hence the build to fail due to -Werror. Then again I'm sure we have ample uses of casts left which are actually bogus.

Quoted 1 line

U9) Conversion between function pointers and object pointers.

Uses I'm readily aware of are deliberate. Plus isn't this shorthand for going through uintptr_t intermediately only anyway?

Quoted 2 lines

U10) \m escape sequence.
Is this an undocumented GCC extension or just a typo?

Where did you find such? The only instances I can spot are in assembler-only constructs, where 'm' really starts the name of an assembler macro argument. Iirc when the compiler pre-processes assembly files (identified by being named *.S or use of the option "-x assembler"), it applies relaxed handling of \ found inside double quotes.

Then again I find it unlikely that you would have meant those, as they're inside #ifdef __ASSEMBLY__ (or alike) guarded sections, and hence shouldn't pop out when analysis tools are run on the tree.

Quoted 1 line

Here is a list of extensions that are documented in the GCC manual:

I suppose that this list wasn't meant to be complete? The most prominent example is probably asm().

Jan

#8 lore raw
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Roberto Bagnara

U1) Use of _Static_assert in C99 mode.

U2) Empty initialization lists, both in C99 mode (ARM64 and X86_64)

      and C18 mode (only X86_64).
Quoted 7 lines
Quoted 1 line

U3) Returning void expressions.

As per above, tiny extensions like these are, I think, unlikely to be mentioned anywhere explicitly (or more than in passing). For the last of the three it may further be that it pre-dates when gcc started to properly document extensions. Oh, actually - U3 is documented along with -Wreturn-type.

Noted: thanks!

Quoted 2 lines

Uses are generally intentional afaik, but eliminating cases of U2 and U3 would likely be possible with just slight overall impact.

Ok. As this has an impact on MISRA compliance at some stage we will need an official position on the subject.

Quoted 1 line

As to U2, it's not clear why you distinguish C99 and C18 mode.

I specified that because for MISRA compliance we need to stick to one version of the language: while most translation units are compiled in C99 mode, some are compiled in C18 mode and some in C90 mode. However, I agree this is OT for the current discussion.

Quoted 4 lines

Throughout
this summary of yours it would likely have been helpful if an example was provided for the behavior your describing, when the wording doesn't make it crystal clear (e.g. no example needed for U1 and U3 above).

You are right: here are a few examples for U2:

xen/arch/arm/cpuerrata.c:92.12-92.35:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/spinlock.h:31.21-31.23: expanded from macro _LOCK_DEBUG'
xen/include/xen/spinlock.h:143.57-143.67: expanded from macro `SPIN_LOCK_UNLOCKED'
xen/include/xen/spinlock.h:144.43-144.60: expanded from macro `DEFINE_SPINLOCK'

xen/arch/arm/cpuerrata.c:678.5-678.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/cpufeature.c:33.5-33.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Quoted 7 lines

As to U1, I'm afraid this statement very early in gcc's section documenting C extensions simply hasn't been properly updated for newer versions of the standard: "Some features that are in ISO C99 but not C90 or C++ are also, as extensions, accepted by GCC in C90 mode and in C++." A somewhat similar statement in the middle of 2.1 "C Language" is slightly better, thus covering at least the specific case of _Static_assert.

Noted: thanks!

Quoted 11 lines
Quoted 2 lines

U4) Static functions or variables used in inline functions with external
linkage.

There's not a lot of "extern inline" that we've accumulated so far, I think. The only ones I'm aware of are sort() and bsearch(), and there the use is precisely for allowing the compiler to optimize away function calls.

The documentation of this functionality is that of the gnu_inline function attribute, afaict. That would be 6.33.1 "Common Function Attributes" in 13.1.0 doc.

No, it is not that one:

xen/common/spinlock.c:316.29-316.40:
static function `observe_head(spinlock_tickets_t*)' is used in an inline function with external linkage (ill-formed for the C99 standard, ISO/IEC 9899:1999: "An ill-formed source detected by the parser." [STD.diag/ext_internal_in_extern_inline_quiet]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12' xen/common/spinlock.c:301.26-301.37:
`observe_head(spinlock_tickets_t*)' declared here
xen/include/xen/spinlock.h:180.1-180.4:
use 'static' to give inline function `_spin_lock_cb(spinlock_t*, void(*)(void*), void*)' internal linkage

Quoted 1 line
Quoted 1 line

U5) Enumerator values outside the range of `int'.

Examples:

xen/arch/x86/include/asm/guest/hyperv-tlfs.h:477.9-477.26: Loc #1 [culprit: ISO C restricts enumerator values to range of 'int' (2147483648 is too large) (ill-formed for the C99 standard, ISO/IEC 9899:1999: "An ill-formed source detected by the parser." [STD.diag/ext_enum_value_not_int]). Tool used is `/usr/bin/x86_64-linux-gnu-gcc-12'] xen/arch/x86/include/asm/guest/hyperv-tlfs.h:477.43-477.52: Loc #2 [evidence: ISO C restricts enumerator values to range of 'int' (2147483648 is too large)]

xen/arch/x86/include/asm/guest/hyperv-tlfs.h:478.9-478.27: Loc #1 [culprit: ISO C restricts enumerator values to range of 'int' (2147483649 is too large) (ill-formed for the C99 standard, ISO/IEC 9899:1999: "An ill-formed source detected by the parser." [STD.diag/ext_enum_value_not_int]). Tool used is `/usr/bin/x86_64-linux-gnu-gcc-12'] xen/arch/x86/include/asm/guest/hyperv-tlfs.h:478.43-478.52: Loc #2 [evidence: ISO C restricts enumerator values to range of 'int' (2147483649 is too large)]

xen/arch/x86/include/asm/hvm/svm/vmcb.h:143.5-143.27: Loc #1 [culprit: ISO C restricts enumerator values to range of 'int' (2147483648 is too large) (ill-formed for the C99 standard, ISO/IEC 9899:1999: "An ill-formed source detected by the parser." [STD.diag/ext_enum_value_not_int]). Tool used is `/usr/bin/x86_64-linux-gnu-gcc-12'] xen/arch/x86/include/asm/hvm/svm/vmcb.h:143.31-143.38: Loc #2 [evidence: ISO C restricts enumerator values to range of 'int' (2147483648 is too large)]

Quoted 1 line
Quoted 1 line

U6) Empty declarations.

Examples:

xen/arch/arm/arm64/lib/find_next_bit.c:57.29:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/arm64/lib/find_next_bit.c:103.34:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/include/asm/vreg.h:143.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/include/asm/vreg.h:144.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/include/asm/arm64/flushtlb.h:70.51:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Quoted 1 line
Quoted 1 line

U7) Empty enum definitions.

Example:

xen/arch/arm/include/asm/vgic.h:275.6-275.17:
enum declaration gic_sgi_mode' is incomplete (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.2.2: "An incomplete enum declaration." [STD.emptenum]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12'

Quoted 2 lines

... here I wonder whether instead you mean forward declaration of enums (i.e. what the standard allows for structures and unions only).

It is reported as an enum forward declaration if the enum is later properly declared. My understanding is that this is not the case for the example above.

Quoted 6 lines
Quoted 1 line

U8) Conversion between incompatible pointer types.

Do we have any uses that aren't, by using casts, documenting that the conversions are deliberate? Otherwise I would expect the compiler to warn, and hence the build to fail due to -Werror. Then again I'm sure we have ample uses of casts left which are actually bogus.

Examples:

xen/common/kernel.c:552.18-552.47:
implicit cast converts from const __typeof__(*(&params))*' (that is const struct xen_platform_parameters*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:65.23-65.24: expanded from macro `copy_to_guest_offset'
xen/include/xen/guest_access.h:104.5-104.41: expanded from macro `copy_to_guest'

xen/common/kernel.c:566.14-566.59:
implicit cast converts from const __typeof__(*(chgset))*' (that is const char*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:65.23-65.24: expanded from macro `copy_to_guest_offset'
xen/include/xen/guest_access.h:104.5-104.41: expanded from macro `copy_to_guest'

xen/common/kernel.c:613.14-613.41:
implicit cast converts from const __typeof__(*(&fi))*' (that is const struct xen_feature_info*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:123.23-123.24: expanded from macro `__copy_to_guest_offset'
xen/include/xen/guest_access.h:152.5-152.43: expanded from macro `__copy_to_guest'

xen/common/kernel.c:645.14-645.71:
implicit cast converts from const __typeof__(*(deny ? xen_deny() : saved_cmdline))*' (that is const char*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:65.23-65.24: expanded from macro `copy_to_guest_offset'
xen/include/xen/guest_access.h:104.5-104.41: expanded from macro `copy_to_guest'

xen/common/memory.c:1745.20-1745.53:
implicit cast converts from const __typeof__(*(&topology))*' (that is const struct xen_vnuma_topology_info*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:123.23-123.24: expanded from macro `__copy_to_guest_offset'
xen/include/xen/guest_access.h:152.5-152.43: expanded from macro `__copy_to_guest'

xen/common/memory.c:1808.14-1808.47:
implicit cast converts from const __typeof__(*(&topology))*' (that is const struct xen_vnuma_topology_info*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:123.23-123.24: expanded from macro `__copy_to_guest_offset'
xen/include/xen/guest_access.h:152.5-152.43: expanded from macro `__copy_to_guest'

xen/common/memory.c:1841.14-1841.47:
implicit cast converts from const __typeof__(*(&grdm.map))*' (that is const struct xen_reserved_device_memory_map*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:123.23-123.24: expanded from macro `__copy_to_guest_offset'
xen/include/xen/guest_access.h:152.5-152.43: expanded from macro `__copy_to_guest'

xen/common/efi/boot.c:335.16-335.56:
implicit cast converts from const CHAR16*' (that is const unsigned short*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12'

xen/common/libfdt/fdt_overlay.c:733.69-733.87:
implicit cast converts from const char*' to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Quoted 1 line
Quoted 1 line

U9) Conversion between function pointers and object pointers.

Example:
xen/arch/x86/apic.c:1159.16-1159.55: Loc #1 [culprit: c_style cast converts from const void*' to unsigned(*)(void)' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Annex J.5.7: "A pointer to a function is converted to a pointer to an object or a pointer to an object is converted to a pointer to a function (6.5.4, 6.3.2.3)." [STD.funojptr]). Tool used is `/usr/bin/x86_64-linux-gnu-gcc-12']

Quoted 2 lines

Uses I'm readily aware of are deliberate. Plus isn't this shorthand for going through uintptr_t intermediately only anyway?

I don't understand the last sentence.

Quoted 2 lines
Quoted 2 lines

U10) \m escape sequence.
Is this an undocumented GCC extension or just a typo?

Already dealt with in another message.

Quoted 4 lines
Quoted 1 line

Here is a list of extensions that are documented in the GCC manual:

I suppose that this list wasn't meant to be complete? The most prominent example is probably asm().

As far as I can tell the list was almost complete (I realize now that the use of the keyword __signed__ was omitted because investigation was not completed). But I am probably misunderstanding you.

Kind regards,

Roberto

#9 lore raw
Quoted 9 lines · Roberto Bagnara
Quoted 4 lines
Quoted 1 line

Here is a list of extensions that are documented in the GCC manual:

I suppose that this list wasn't meant to be complete? The most prominent example is probably asm().

As far as I can tell the list was almost complete (I realize now that the use of the keyword __signed__ was omitted because investigation was not completed). But I am probably misunderstanding you.

We also make use of the following extensions (please correct me if I am wrong and these are not extensions):

xen/include/xen/compiler.h:#define always_inline __inline__ __attribute__ ((__always_inline__))

xen/include/xen/compiler.h:#define gnu_inline    __inline__ __attribute__ ((__gnu_inline__))
xen/include/xen/compiler.h:#define noinline      __attribute__((__noinline__))
xen/include/xen/compiler.h:#define noreturn      __attribute__((__noreturn__))
xen/include/xen/compiler.h:#define __packed      __attribute__((__packed__))
xen/include/xen/compiler.h:#define __weak        __attribute__((__weak__))
xen/include/xen/compiler.h:# define nocall       __attribute__((__error__("Nonstandard ABI")))
xen/include/xen/compiler.h:# define cf_check     __attribute__((__cf_check__))

xen/include/xen/compiler.h:# define fallthrough __attribute__((__fallthrough__))
xen/include/xen/compiler.h:#define __aligned(a) __attribute__((__aligned__(a))) xen/include/xen/compiler.h:#define __attribute_pure__ __attribute__((__pure__)) xen/include/xen/compiler.h:#define __attribute_const__ __attribute__((__const__))
xen/include/xen/compiler.h:#define __transparent__ __attribute__((__transparent_union__))
xen/include/xen/compiler.h:#define __used __attribute__((__used__))
xen/include/xen/compiler.h:#define __maybe_unused __attribute__((__unused__)) xen/include/xen/compiler.h:#define __must_check __attribute__((__warn_unused_result__)) xen/include/xen/compiler.h:#define __nonnull(...) __attribute__((__nonnull__(__VA_ARGS__)))

It is possible that some of these don't show up in any of the relevant code build as part of the minimal configuration for safety so you won't see any errors/warnings in Eclair.

Also, some of these extensions are probably no longer necessary, such as __gnu_inline__.

#10 lore raw
Quoted 32 lines · Stefano Stabellini
Quoted 9 lines · Roberto Bagnara
Quoted 4 lines
Quoted 1 line

Here is a list of extensions that are documented in the GCC manual:

I suppose that this list wasn't meant to be complete? The most prominent example is probably asm().

As far as I can tell the list was almost complete (I realize now that the use of the keyword __signed__ was omitted because investigation was not completed). But I am probably misunderstanding you.

We also make use of the following extensions (please correct me if I am wrong and these are not extensions):

xen/include/xen/compiler.h:#define always_inline __inline__ __attribute__ ((__always_inline__))

xen/include/xen/compiler.h:#define gnu_inline    __inline__ __attribute__ ((__gnu_inline__))
xen/include/xen/compiler.h:#define noinline      __attribute__((__noinline__))
xen/include/xen/compiler.h:#define noreturn      __attribute__((__noreturn__))
xen/include/xen/compiler.h:#define __packed      __attribute__((__packed__))
xen/include/xen/compiler.h:#define __weak        __attribute__((__weak__))
xen/include/xen/compiler.h:# define nocall       __attribute__((__error__("Nonstandard ABI")))
xen/include/xen/compiler.h:# define cf_check     __attribute__((__cf_check__))

xen/include/xen/compiler.h:# define fallthrough __attribute__((__fallthrough__))
xen/include/xen/compiler.h:#define __aligned(a) __attribute__((__aligned__(a))) xen/include/xen/compiler.h:#define __attribute_pure__ __attribute__((__pure__)) xen/include/xen/compiler.h:#define __attribute_const__ __attribute__((__const__))
xen/include/xen/compiler.h:#define __transparent__ __attribute__((__transparent_union__))
xen/include/xen/compiler.h:#define __used __attribute__((__used__))
xen/include/xen/compiler.h:#define __maybe_unused __attribute__((__unused__)) xen/include/xen/compiler.h:#define __must_check __attribute__((__warn_unused_result__)) xen/include/xen/compiler.h:#define __nonnull(...) __attribute__((__nonnull__(__VA_ARGS__)))

Quoted 6 lines

It is possible that some of these don't show up in any of the relevant code build as part of the minimal configuration for safety so you won't see any errors/warnings in Eclair.

Also, some of these extensions are probably no longer necessary, such as __gnu_inline__.

gnu_inline was already noticed as in use - see bsearch() and sort(). Iirc Andrew in particular wants it used in further places.

Jan

#11 lore raw
In reply to Roberto Bagnara
Quoted 35 lines · Roberto Bagnara
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Roberto Bagnara

U1) Use of _Static_assert in C99 mode.

U2) Empty initialization lists, both in C99 mode (ARM64 and X86_64)

      and C18 mode (only X86_64).
Quoted 7 lines
Quoted 1 line

U3) Returning void expressions.

As per above, tiny extensions like these are, I think, unlikely to be mentioned anywhere explicitly (or more than in passing). For the last of the three it may further be that it pre-dates when gcc started to properly document extensions. Oh, actually - U3 is documented along with -Wreturn-type.

Noted: thanks!

Quoted 2 lines

Uses are generally intentional afaik, but eliminating cases of U2 and U3 would likely be possible with just slight overall impact.

Ok. As this has an impact on MISRA compliance at some stage we will need an official position on the subject.

Quoted 1 line

As to U2, it's not clear why you distinguish C99 and C18 mode.

I specified that because for MISRA compliance we need to stick to one version of the language: while most translation units are compiled in C99 mode, some are compiled in C18 mode and some in C90 mode. However, I agree this is OT for the current discussion.

Quoted 4 lines

Throughout
this summary of yours it would likely have been helpful if an example was provided for the behavior your describing, when the wording doesn't make it crystal clear (e.g. no example needed for U1 and U3 above).

Quoted 7 lines

You are right: here are a few examples for U2:

xen/arch/arm/cpuerrata.c:92.12-92.35:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/spinlock.h:31.21-31.23: expanded from macro _LOCK_DEBUG'
xen/include/xen/spinlock.h:143.57-143.67: expanded from macro `SPIN_LOCK_UNLOCKED'
xen/include/xen/spinlock.h:144.43-144.60: expanded from macro `DEFINE_SPINLOCK'

I'm afraid this is a bad example, as it goes hand-in-hand with using another extension. I don't think using a non-empty initialization list is going to work with

union lock_debug { };

Quoted 5 lines

xen/arch/arm/cpuerrata.c:678.5-678.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/cpufeature.c:33.5-33.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Both of these are a common idiom we use: The "sentinel" of an array of compound type initializer.

Quoted 12 lines
Quoted 11 lines
Quoted 2 lines

U4) Static functions or variables used in inline functions with external
linkage.

There's not a lot of "extern inline" that we've accumulated so far, I think. The only ones I'm aware of are sort() and bsearch(), and there the use is precisely for allowing the compiler to optimize away function calls.

The documentation of this functionality is that of the gnu_inline function attribute, afaict. That would be 6.33.1 "Common Function Attributes" in 13.1.0 doc.

Quoted 8 lines

No, it is not that one:

xen/common/spinlock.c:316.29-316.40:
static function `observe_head(spinlock_tickets_t*)' is used in an inline function with external linkage (ill-formed for the C99 standard, ISO/IEC 9899:1999: "An ill-formed source detected by the parser." [STD.diag/ext_internal_in_extern_inline_quiet]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12' xen/common/spinlock.c:301.26-301.37:
`observe_head(spinlock_tickets_t*)' declared here
xen/include/xen/spinlock.h:180.1-180.4:
use 'static' to give inline function `_spin_lock_cb(spinlock_t*, void(*)(void*), void*)' internal linkage

Oh, I see. I guess by introducing another wrapper we could deal with that in sufficiently unintrusive a way.

Quoted 9 lines
Quoted 1 line
Quoted 1 line

U5) Enumerator values outside the range of `int'.

Examples:

xen/arch/x86/include/asm/guest/hyperv-tlfs.h:477.9-477.26: Loc #1 [culprit: ISO C restricts enumerator values to range of 'int' (2147483648 is too large) (ill-formed for the C99 standard, ISO/IEC 9899:1999: "An ill-formed source detected by the parser." [STD.diag/ext_enum_value_not_int]). Tool used is `/usr/bin/x86_64-linux-gnu-gcc-12'] xen/arch/x86/include/asm/guest/hyperv-tlfs.h:477.43-477.52: Loc #2 [evidence: ISO C restricts enumerator values to range of 'int' (2147483648 is too large)]

xen/arch/x86/include/asm/guest/hyperv-tlfs.h:478.9-478.27: Loc #1 [culprit: ISO C restricts enumerator values to range of 'int' (2147483649 is too large) (ill-formed for the C99 standard, ISO/IEC 9899:1999: "An ill-formed source detected by the parser." [STD.diag/ext_enum_value_not_int]). Tool used is `/usr/bin/x86_64-linux-gnu-gcc-12'] xen/arch/x86/include/asm/guest/hyperv-tlfs.h:478.43-478.52: Loc #2 [evidence: ISO C restricts enumerator values to range of 'int' (2147483649 is too large)]

It's not entirely clear to me in how far hyperv-tlfs.h is a header fully of our own. It may be possible to switch to #define instead if we don't "follow" someone else's header.

Quoted 2 lines

xen/arch/x86/include/asm/hvm/svm/vmcb.h:143.5-143.27: Loc #1 [culprit: ISO C restricts enumerator values to range of 'int' (2147483648 is too large) (ill-formed for the C99 standard, ISO/IEC 9899:1999: "An ill-formed source detected by the parser." [STD.diag/ext_enum_value_not_int]). Tool used is `/usr/bin/x86_64-linux-gnu-gcc-12'] xen/arch/x86/include/asm/hvm/svm/vmcb.h:143.31-143.38: Loc #2 [evidence: ISO C restricts enumerator values to range of 'int' (2147483648 is too large)]

Here we have more leeway, and imo the offending enumerations are an abuse of "enum" in the first place.

Quoted 9 lines
Quoted 1 line
Quoted 1 line

U6) Empty declarations.

Examples:

xen/arch/arm/arm64/lib/find_next_bit.c:57.29:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/arm64/lib/find_next_bit.c:103.34:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Looks like these could be taken care of by finally purging our EXPORT_SYMBOL() stub.

Quoted 5 lines

xen/arch/arm/include/asm/vreg.h:143.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/include/asm/vreg.h:144.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

I'm having trouble spotting anything suspicious there.

Quoted 2 lines

xen/arch/arm/include/asm/arm64/flushtlb.h:70.51:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Same here. I the tool having an issue with the instantiation of (inline) functions by way of a macro?

Quoted 7 lines
Quoted 1 line
Quoted 1 line

U7) Empty enum definitions.

Example:

xen/arch/arm/include/asm/vgic.h:275.6-275.17:
enum declaration gic_sgi_mode' is incomplete (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.2.2: "An incomplete enum declaration." [STD.emptenum]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12'

Quoted 6 lines
Quoted 2 lines

... here I wonder whether instead you mean forward declaration of enums (i.e. what the standard allows for structures and unions only).

It is reported as an enum forward declaration if the enum is later properly declared. My understanding is that this is not the case for the example above.

asm/gic.h provides the full definition. There looks to be exactly one case (smp.c) where asm/vgic.h is included but asm/gic.h isn't. As there may be peculiarities to this, Arm maintainers would need to take a look to decide whether also including the other header that is an option.

Quoted 39 lines
Quoted 6 lines
Quoted 1 line

U8) Conversion between incompatible pointer types.

Do we have any uses that aren't, by using casts, documenting that the conversions are deliberate? Otherwise I would expect the compiler to warn, and hence the build to fail due to -Werror. Then again I'm sure we have ample uses of casts left which are actually bogus.

Examples:

xen/common/kernel.c:552.18-552.47:
implicit cast converts from const __typeof__(*(&params))*' (that is const struct xen_platform_parameters*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:65.23-65.24: expanded from macro `copy_to_guest_offset'
xen/include/xen/guest_access.h:104.5-104.41: expanded from macro `copy_to_guest'

xen/common/kernel.c:566.14-566.59:
implicit cast converts from const __typeof__(*(chgset))*' (that is const char*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:65.23-65.24: expanded from macro `copy_to_guest_offset'
xen/include/xen/guest_access.h:104.5-104.41: expanded from macro `copy_to_guest'

xen/common/kernel.c:613.14-613.41:
implicit cast converts from const __typeof__(*(&fi))*' (that is const struct xen_feature_info*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:123.23-123.24: expanded from macro `__copy_to_guest_offset'
xen/include/xen/guest_access.h:152.5-152.43: expanded from macro `__copy_to_guest'

xen/common/kernel.c:645.14-645.71:
implicit cast converts from const __typeof__(*(deny ? xen_deny() : saved_cmdline))*' (that is const char*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:65.23-65.24: expanded from macro `copy_to_guest_offset'
xen/include/xen/guest_access.h:104.5-104.41: expanded from macro `copy_to_guest'

xen/common/memory.c:1745.20-1745.53:
implicit cast converts from const __typeof__(*(&topology))*' (that is const struct xen_vnuma_topology_info*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:123.23-123.24: expanded from macro `__copy_to_guest_offset'
xen/include/xen/guest_access.h:152.5-152.43: expanded from macro `__copy_to_guest'

xen/common/memory.c:1808.14-1808.47:
implicit cast converts from const __typeof__(*(&topology))*' (that is const struct xen_vnuma_topology_info*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:123.23-123.24: expanded from macro `__copy_to_guest_offset'
xen/include/xen/guest_access.h:152.5-152.43: expanded from macro `__copy_to_guest'

Quoted 4 lines

xen/common/memory.c:1841.14-1841.47:
implicit cast converts from const __typeof__(*(&grdm.map))*' (that is const struct xen_reserved_device_memory_map*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/guest_access.h:123.23-123.24: expanded from macro `__copy_to_guest_offset'
xen/include/xen/guest_access.h:152.5-152.43: expanded from macro `__copy_to_guest'

These are all a common pattern. Line 65 in xen/guest_access.h is

    (void)((hnd).p == _s);                              \

i.e. not an assignment in the first place. Nearby assignments don't involve _s, yet that's pretty clearly what is being referred to by const __typeof__(*(...))*. In pointer comparisons, differring qualifiers are okay afaik (6.5.9), so I wonder whether the tool is becoming confused here.

I don't know the acronyms used, but isn't STD.pteincmp referring to comparisons rather that assignments?

Quoted 2 lines

xen/common/efi/boot.c:335.16-335.56:
implicit cast converts from const CHAR16*' (that is const unsigned short*') to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12'

Same here - comparison of the result of wmemchr() (const CHAR16*) with an expression derived from "data" (void*).

Quoted 2 lines

xen/common/libfdt/fdt_overlay.c:733.69-733.87:
implicit cast converts from const char*' to void*' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.5.16.1: "Implicit conversion from a pointer to an incompatible pointer." [STD.pteincmp]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Same here again, I think.

Quoted 9 lines
Quoted 1 line
Quoted 1 line

U9) Conversion between function pointers and object pointers.

Example:
xen/arch/x86/apic.c:1159.16-1159.55: Loc #1 [culprit: c_style cast converts from const void*' to unsigned(*)(void)' (ill-formed for the C99 standard, ISO/IEC 9899:1999 Annex J.5.7: "A pointer to a function is converted to a pointer to an object or a pointer to an object is converted to a pointer to a function (6.5.4, 6.3.2.3)." [STD.funojptr]). Tool used is `/usr/bin/x86_64-linux-gnu-gcc-12']

Quoted 2 lines

Uses I'm readily aware of are deliberate. Plus isn't this shorthand for going through uintptr_t intermediately only anyway?

I don't understand the last sentence.

6.3.2.3 allows conversions between integer and pointer types. Hence isn't intermediately going through uintptr_t merely a more verbose way of casting between function and object pointers directly:

    ptr = (void *)(uintptr_t)func;

vs

    ptr = (void *)func;

?

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

Here is a list of extensions that are documented in the GCC manual:

I suppose that this list wasn't meant to be complete? The most prominent example is probably asm().

As far as I can tell the list was almost complete (I realize now that the use of the keyword __signed__ was omitted because investigation was not completed). But I am probably misunderstanding you.

Well, your list didn't include asm(), which is an extension we can't do without. We also use __attribute__(()) extensively. And while hunting for extensions which aren't documented in their own dedicated sections, I think I had come across more. I didn't write these down, and if at all possible I'd prefer to avoid repeating the exercise.

Jan

#12 lore raw
Quoted 11 lines · Jan Beulich
Quoted 9 lines · Roberto Bagnara
Quoted 1 line · Jan Beulich

On 05.06.2023 07:28, Roberto Bagnara wrote:

You are right: here are a few examples for U2:

xen/arch/arm/cpuerrata.c:92.12-92.35:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/spinlock.h:31.21-31.23: expanded from macro _LOCK_DEBUG'
xen/include/xen/spinlock.h:143.57-143.67: expanded from macro `SPIN_LOCK_UNLOCKED'
xen/include/xen/spinlock.h:144.43-144.60: expanded from macro `DEFINE_SPINLOCK'

Quoted 5 lines

I'm afraid this is a bad example, as it goes hand-in-hand with using another extension. I don't think using a non-empty initialization list is going to work with

union lock_debug { };

Yes, this is C99 undefined behavior 58:
"A structure or union is defined as containing no named members (6.7.2.1)."

Here is another example:

lpae_t pte = {};

whereas we have

typedef union {
    uint64_t bits;
    lpae_pt_t pt;
    lpae_p2m_t p2m;
    lpae_walk_t walk;
} lpae_t;
Quoted 8 lines
Quoted 5 lines

xen/arch/arm/cpuerrata.c:678.5-678.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/cpufeature.c:33.5-33.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Both of these are a common idiom we use: The "sentinel" of an array of compound type initializer.

Wouldn't it be possible writing such sentinels in a standard-compliant way, like {0} or similar, instead of {}?

Quoted 13 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line

U6) Empty declarations.

Examples:

xen/arch/arm/arm64/lib/find_next_bit.c:57.29:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/arm64/lib/find_next_bit.c:103.34:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Looks like these could be taken care of by finally purging our EXPORT_SYMBOL() stub.

Quoted 7 lines
Quoted 5 lines

xen/arch/arm/include/asm/vreg.h:143.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/include/asm/vreg.h:144.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

I'm having trouble spotting anything suspicious there.

The macro expands to definitions of inline functions and after the macro invocation there is a ";".

The preprocessed code is then:

static inline void foo() { ... }
;

where the final ";" is an empty declaration not allowed by the C99 language standard.

Removing the ";" after the macro invocation is a possible solution, but other possibilities exist if this is strongly unwanted.

We are preparing a new list in RST format, which would go under docs/misra and constitute a more convenient way for the community to take note of the used extensions and contribute to the discussion about their adequacy.

#13 lore raw
Quoted 38 lines · Roberto Bagnara
Quoted 11 lines · Jan Beulich
Quoted 9 lines · Roberto Bagnara
Quoted 1 line · Jan Beulich

On 05.06.2023 07:28, Roberto Bagnara wrote:

You are right: here are a few examples for U2:

xen/arch/arm/cpuerrata.c:92.12-92.35:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/spinlock.h:31.21-31.23: expanded from macro _LOCK_DEBUG'
xen/include/xen/spinlock.h:143.57-143.67: expanded from macro `SPIN_LOCK_UNLOCKED'
xen/include/xen/spinlock.h:144.43-144.60: expanded from macro `DEFINE_SPINLOCK'

Quoted 5 lines

I'm afraid this is a bad example, as it goes hand-in-hand with using another extension. I don't think using a non-empty initialization list is going to work with

union lock_debug { };

Yes, this is C99 undefined behavior 58:
"A structure or union is defined as containing no named members (6.7.2.1)."

Here is another example:

lpae_t pte = {};

whereas we have

typedef union {
     uint64_t bits;
     lpae_pt_t pt;
     lpae_p2m_t p2m;
     lpae_walk_t walk;
} lpae_t;
Quoted 3 lines
Quoted 3 lines

xen/arch/arm/cpuerrata.c:678.5-678.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

xen/arch/arm/cpufeature.c:33.5-33.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Both of these are a common idiom we use: The "sentinel" of an array of compound type initializer.

Wouldn't it be possible writing such sentinels in a standard-compliant way, like {0} or similar, instead of {}?

I would be possible, sure, but the question is whether we want that. Iirc in review comments we've been asking to preferably use {}, for being shorter / less clutter without resulting in any ambiguity.

Quoted 24 lines
Quoted 13 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line

U6) Empty declarations.

Examples:

xen/arch/arm/arm64/lib/find_next_bit.c:57.29:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/arm64/lib/find_next_bit.c:103.34:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Looks like these could be taken care of by finally purging our EXPORT_SYMBOL() stub.

Quoted 7 lines
Quoted 5 lines

xen/arch/arm/include/asm/vreg.h:143.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/include/asm/vreg.h:144.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

I'm having trouble spotting anything suspicious there.

The macro expands to definitions of inline functions and after the macro invocation there is a ";".

Quoted 7 lines

The preprocessed code is then:

static inline void foo() { ... }
;

where the final ";" is an empty declaration not allowed by the C99 language standard.

Oh, I see.

Quoted 2 lines

Removing the ";" after the macro invocation is a possible solution, but other possibilities exist if this is strongly unwanted.

We have other macros to instantiate functions, and there no stray semicolons are used. I think this wants doing the same way here, but it being Arm code the ultimate say is with the Arm maintainers.

Jan

#14 lore raw
Quoted 86 lines · Jan Beulich
Quoted 38 lines · Roberto Bagnara
Quoted 11 lines · Jan Beulich
Quoted 9 lines · Roberto Bagnara
Quoted 1 line · Jan Beulich

On 05.06.2023 07:28, Roberto Bagnara wrote:

You are right: here are a few examples for U2:

xen/arch/arm/cpuerrata.c:92.12-92.35:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/spinlock.h:31.21-31.23: expanded from macro _LOCK_DEBUG'
xen/include/xen/spinlock.h:143.57-143.67: expanded from macro `SPIN_LOCK_UNLOCKED'
xen/include/xen/spinlock.h:144.43-144.60: expanded from macro `DEFINE_SPINLOCK'

Quoted 5 lines

I'm afraid this is a bad example, as it goes hand-in-hand with using another extension. I don't think using a non-empty initialization list is going to work with

union lock_debug { };

Yes, this is C99 undefined behavior 58:
"A structure or union is defined as containing no named members (6.7.2.1)."

Here is another example:

lpae_t pte = {};

whereas we have

typedef union {
     uint64_t bits;
     lpae_pt_t pt;
     lpae_p2m_t p2m;
     lpae_walk_t walk;
} lpae_t;
Quoted 3 lines
Quoted 3 lines

xen/arch/arm/cpuerrata.c:678.5-678.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

xen/arch/arm/cpufeature.c:33.5-33.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Both of these are a common idiom we use: The "sentinel" of an array of compound type initializer.

Wouldn't it be possible writing such sentinels in a standard-compliant way, like {0} or similar, instead of {}?

I would be possible, sure, but the question is whether we want that. Iirc in review comments we've been asking to preferably use {}, for being shorter / less clutter without resulting in any ambiguity.

Quoted 24 lines
Quoted 13 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line

U6) Empty declarations.

Examples:

xen/arch/arm/arm64/lib/find_next_bit.c:57.29:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/arm64/lib/find_next_bit.c:103.34:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Looks like these could be taken care of by finally purging our EXPORT_SYMBOL() stub.

Quoted 7 lines
Quoted 5 lines

xen/arch/arm/include/asm/vreg.h:143.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/include/asm/vreg.h:144.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

I'm having trouble spotting anything suspicious there.

The macro expands to definitions of inline functions and after the macro invocation there is a ";".

Quoted 7 lines

The preprocessed code is then:

static inline void foo() { ... }
;

where the final ";" is an empty declaration not allowed by the C99 language standard.

Quoted 8 lines

Oh, I see.

Quoted 2 lines

Removing the ";" after the macro invocation is a possible solution, but other possibilities exist if this is strongly unwanted.

We have other macros to instantiate functions, and there no stray semicolons are used. I think this wants doing the same way here, but it being Arm code the ultimate say is with the Arm maintainers.

Apart from vreg.h the same applies to TLB_HELPER of arm32/arm64. I think also TYPE_SAFE would want to be fixed.

~Michal

#15 lore raw
Quoted 40 lines · Michal Orzel
Quoted 39 lines · Jan Beulich
Quoted 28 lines · Roberto Bagnara
Quoted 16 lines · Jan Beulich
Quoted 11 lines · Roberto Bagnara
Quoted 2 lines · Jan Beulich
Quoted 1 line · Roberto Bagnara

U6) Empty declarations.

Examples:

xen/arch/arm/arm64/lib/find_next_bit.c:57.29:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/arm64/lib/find_next_bit.c:103.34:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Looks like these could be taken care of by finally purging our EXPORT_SYMBOL() stub.

Quoted 7 lines
Quoted 5 lines

xen/arch/arm/include/asm/vreg.h:143.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/include/asm/vreg.h:144.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

I'm having trouble spotting anything suspicious there.

The macro expands to definitions of inline functions and after the macro invocation there is a ";".

Quoted 7 lines

The preprocessed code is then:

static inline void foo() { ... }
;

where the final ";" is an empty declaration not allowed by the C99 language standard.

Oh, I see.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Removing the ";" after the macro invocation is a possible solution, but other possibilities exist if this is strongly unwanted.

We have other macros to instantiate functions, and there no stray semicolons are used. I think this wants doing the same way here, but it being Arm code the ultimate say is with the Arm maintainers.

Apart from vreg.h the same applies to TLB_HELPER of arm32/arm64. I think also TYPE_SAFE would want to be fixed.

Indeed. For this last one I wonder though whether it wouldn't be better to continue to permit (really: require) the semicolon at the use sites, by putting the typedef-s last and omitting the semicolon in the macro definitions.

Jan

#16 lore raw
Quoted 49 lines · Jan Beulich
Quoted 46 lines · Michal Orzel
Quoted 45 lines · Jan Beulich
Quoted 28 lines · Roberto Bagnara
Quoted 16 lines · Jan Beulich
Quoted 11 lines · Roberto Bagnara
Quoted 2 lines · Jan Beulich
Quoted 1 line · Roberto Bagnara

U6) Empty declarations.

Examples:

xen/arch/arm/arm64/lib/find_next_bit.c:57.29:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/arm64/lib/find_next_bit.c:103.34:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Looks like these could be taken care of by finally purging our EXPORT_SYMBOL() stub.

Quoted 7 lines
Quoted 5 lines

xen/arch/arm/include/asm/vreg.h:143.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/include/asm/vreg.h:144.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

I'm having trouble spotting anything suspicious there.

The macro expands to definitions of inline functions and after the macro invocation there is a ";".

Quoted 7 lines

The preprocessed code is then:

static inline void foo() { ... }
;

where the final ";" is an empty declaration not allowed by the C99 language standard.

Oh, I see.

Quoted 2 lines

Removing the ";" after the macro invocation is a possible solution, but other possibilities exist if this is strongly unwanted.

We have other macros to instantiate functions, and there no stray semicolons are used. I think this wants doing the same way here, but it being Arm code the ultimate say is with the Arm maintainers.

Quoted 7 lines
Quoted 2 lines

Apart from vreg.h the same applies to TLB_HELPER of arm32/arm64. I think also TYPE_SAFE would want to be fixed.

Indeed. For this last one I wonder though whether it wouldn't be better to continue to permit (really: require) the semicolon at the use sites, by putting the typedef-s last and omitting the semicolon in the macro definitions.

This would be an error I think since the functions are defined using this type so it must be defined first. Unless there is a way to forward typedef. All in all, removing semicolon at use sites is simpler.

~Michal

#17 lore raw
Quoted 55 lines · Michal Orzel
Quoted 52 lines · Jan Beulich
Quoted 48 lines · Michal Orzel
Quoted 37 lines · Jan Beulich
Quoted 28 lines · Roberto Bagnara
Quoted 16 lines · Jan Beulich
Quoted 11 lines · Roberto Bagnara
Quoted 2 lines · Jan Beulich
Quoted 1 line · Roberto Bagnara

U6) Empty declarations.

Examples:

xen/arch/arm/arm64/lib/find_next_bit.c:57.29:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/arm64/lib/find_next_bit.c:103.34:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Looks like these could be taken care of by finally purging our EXPORT_SYMBOL() stub.

Quoted 7 lines
Quoted 5 lines

xen/arch/arm/include/asm/vreg.h:143.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/include/asm/vreg.h:144.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

I'm having trouble spotting anything suspicious there.

The macro expands to definitions of inline functions and after the macro invocation there is a ";".

Quoted 7 lines

The preprocessed code is then:

static inline void foo() { ... }
;

where the final ";" is an empty declaration not allowed by the C99 language standard.

Quoted 8 lines

Oh, I see.

Quoted 2 lines

Removing the ";" after the macro invocation is a possible solution, but other possibilities exist if this is strongly unwanted.

We have other macros to instantiate functions, and there no stray semicolons are used. I think this wants doing the same way here, but it being Arm code the ultimate say is with the Arm maintainers.

Apart from vreg.h the same applies to TLB_HELPER of arm32/arm64. I think also TYPE_SAFE would want to be fixed.

Quoted 6 lines
Quoted 4 lines

Indeed. For this last one I wonder though whether it wouldn't be better to continue to permit (really: require) the semicolon at the use sites, by putting the typedef-s last and omitting the semicolon in the macro definitions.

This would be an error I think since the functions are defined using this type so it must be defined first. Unless there is a way to forward typedef.

Well, I didn't make the suggestion without first checking whether that would (likely) be possible.

Quoted 2 lines

All in all,
removing semicolon at use sites is simpler.

Simpler - yes. But syntax-wise I think it is best if, except in special cases, kind-of-statements and kind-of-declarations ended with a semicolon. Special cases would be in particular ones where macro definition and macro use are next to one another.

Jan

#18 lore raw
In reply to Jan Beulich

Hi Jan,

Quoted 84 lines · Jan Beulich
Quoted 38 lines · Roberto Bagnara
Quoted 11 lines · Jan Beulich
Quoted 9 lines · Roberto Bagnara
Quoted 1 line · Jan Beulich

On 05.06.2023 07:28, Roberto Bagnara wrote:

You are right: here are a few examples for U2:

xen/arch/arm/cpuerrata.c:92.12-92.35:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/spinlock.h:31.21-31.23: expanded from macro _LOCK_DEBUG'
xen/include/xen/spinlock.h:143.57-143.67: expanded from macro `SPIN_LOCK_UNLOCKED'
xen/include/xen/spinlock.h:144.43-144.60: expanded from macro `DEFINE_SPINLOCK'

Quoted 5 lines

I'm afraid this is a bad example, as it goes hand-in-hand with using another extension. I don't think using a non-empty initialization list is going to work with

union lock_debug { };

Yes, this is C99 undefined behavior 58:
"A structure or union is defined as containing no named members (6.7.2.1)."

Here is another example:

lpae_t pte = {};

whereas we have

typedef union {
      uint64_t bits;
      lpae_pt_t pt;
      lpae_p2m_t p2m;
      lpae_walk_t walk;
} lpae_t;
Quoted 3 lines
Quoted 3 lines

xen/arch/arm/cpuerrata.c:678.5-678.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

xen/arch/arm/cpufeature.c:33.5-33.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Both of these are a common idiom we use: The "sentinel" of an array of compound type initializer.

Wouldn't it be possible writing such sentinels in a standard-compliant way, like {0} or similar, instead of {}?

I would be possible, sure, but the question is whether we want that. Iirc in review comments we've been asking to preferably use {}, for being shorter / less clutter without resulting in any ambiguity.

Quoted 24 lines
Quoted 13 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line

U6) Empty declarations.

Examples:

xen/arch/arm/arm64/lib/find_next_bit.c:57.29:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/arm64/lib/find_next_bit.c:103.34:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Looks like these could be taken care of by finally purging our EXPORT_SYMBOL() stub.

Quoted 7 lines
Quoted 5 lines

xen/arch/arm/include/asm/vreg.h:143.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/include/asm/vreg.h:144.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

I'm having trouble spotting anything suspicious there.

The macro expands to definitions of inline functions and after the macro invocation there is a ";".

Quoted 7 lines

The preprocessed code is then:

static inline void foo() { ... }
;

where the final ";" is an empty declaration not allowed by the C99 language standard.

Quoted 8 lines

Oh, I see.

Quoted 2 lines

Removing the ";" after the macro invocation is a possible solution, but other possibilities exist if this is strongly unwanted.

We have other macros to instantiate functions, and there no stray semicolons are used. I think this wants doing the same way here, but it being Arm code the ultimate say is with the Arm maintainers.

I don't think there is a reason to keep the ";" after. So I would be fine if this is removed.

Cheers,

Signature · 1 line
Julien Grall
#19 lore raw

Hi,

Quoted 86 lines · Julien Grall

Hi Jan,

Quoted 81 lines · Jan Beulich
Quoted 38 lines · Roberto Bagnara
Quoted 11 lines · Jan Beulich
Quoted 9 lines · Roberto Bagnara
Quoted 1 line · Jan Beulich

On 05.06.2023 07:28, Roberto Bagnara wrote:

You are right: here are a few examples for U2:

xen/arch/arm/cpuerrata.c:92.12-92.35:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is /usr/bin/aarch64-linux-gnu-gcc-12' xen/include/xen/spinlock.h:31.21-31.23: expanded from macro _LOCK_DEBUG'
xen/include/xen/spinlock.h:143.57-143.67: expanded from macro `SPIN_LOCK_UNLOCKED'
xen/include/xen/spinlock.h:144.43-144.60: expanded from macro `DEFINE_SPINLOCK'

Quoted 5 lines

I'm afraid this is a bad example, as it goes hand-in-hand with using another extension. I don't think using a non-empty initialization list is going to work with

union lock_debug { };

Yes, this is C99 undefined behavior 58:
"A structure or union is defined as containing no named members (6.7.2.1)."

Here is another example:

lpae_t pte = {};

whereas we have

typedef union {
     uint64_t bits;
     lpae_pt_t pt;
     lpae_p2m_t p2m;
     lpae_walk_t walk;
} lpae_t;
Quoted 3 lines
Quoted 3 lines

xen/arch/arm/cpuerrata.c:678.5-678.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

xen/arch/arm/cpufeature.c:33.5-33.6:
empty initializer list (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7.8: "An empty initialization list." [STD.emptinit]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Both of these are a common idiom we use: The "sentinel" of an array of compound type initializer.

Wouldn't it be possible writing such sentinels in a standard-compliant way, like {0} or similar, instead of {}?

I would be possible, sure, but the question is whether we want that. Iirc in review comments we've been asking to preferably use {}, for being shorter / less clutter without resulting in any ambiguity.

Quoted 31 lines
Quoted 13 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line

U6) Empty declarations.

Examples:

xen/arch/arm/arm64/lib/find_next_bit.c:57.29:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/arm64/lib/find_next_bit.c:103.34:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

Looks like these could be taken care of by finally purging our EXPORT_SYMBOL() stub.

Quoted 7 lines
Quoted 5 lines

xen/arch/arm/include/asm/vreg.h:143.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

xen/arch/arm/include/asm/vreg.h:144.26:
empty declaration (ill-formed for the C99 standard, ISO/IEC 9899:1999 Section 6.7: "An empty declaration." [STD.emptdecl]). Tool used is `/usr/bin/aarch64-linux-gnu-gcc-12'

I'm having trouble spotting anything suspicious there.

The macro expands to definitions of inline functions and after the macro invocation there is a ";".

The preprocessed code is then:

static inline void foo() { ... }
;

where the final ";" is an empty declaration not allowed by the C99 language standard.

Quoted 8 lines
Quoted 6 lines

Oh, I see.

Quoted 2 lines

Removing the ";" after the macro invocation is a possible solution, but other possibilities exist if this is strongly unwanted.

We have other macros to instantiate functions, and there no stray semicolons are used. I think this wants doing the same way here, but it being Arm code the ultimate say is with the Arm maintainers.

I don't think there is a reason to keep the ";" after. So I would be fine if this is removed.

+1

Cheers
Bertrand