sparse: add support for _Static_assert
PATCH v7 1/1 sparse: add support for _Static_assert
This patch introduces support for the C11 _Static_assert() construct.
Per the N1539 draft standard, the syntax changes for this construct include:
declaration:
<declaration-specifiers> <init-declarator-list>[opt] ;
<static_assert-declaration>
struct-declaration:
<specifier-qualifier-list> <struct-declarator-list>[opt] ;
<static_assert-declaration>
static_assert-declaration:
_Static_assert ( <constant-expression> , <string-literal> ) ;---
v7: Incorporated additional feedback from Christopher Li and
Luc van Oostenryck. Tested via "make check", also redefined Linux compiletime_assert() to use _Static_assert() when running sparse (gcc had issues with _Static_assert() in *.s files), no additional warnings were emitted.
v6: Incorporated feedback from Christopher Li, improved tests.
- rebased on sparse-next branch
- use match_ident(), eliminated match_static_assert()
- reworked parse_static_assert() for better error reporting. introduced "errtok" variable to accurately report error column.
- Moved static assert parsing in statement_list() for better readability, use "continue" to avoid duplicating lines.
- Fixed whitespace issues (from "git am") in static_assert.c.
- Added test cases for missing conditional expression and missing diagnostic string.
v5: Incorporated feedback from Christopher Li and Luc van Oostenryck:
- Made _Static_assert a reserved identifier
- Simplified check for _Static_assert keyword, consolidated into a common function.
- Improved the "static assert within a function body" test case by adding a static assertion intermingled with code and adding a static assertion within a compound statement block.
- Fixed use of initialized stmt variable.
Tested by using sparse on entire kernel tree and a similarly-sized code tree which makes use of _Static_assert().
v4: Addressed feedback, simplified and restructured to better model
description in draft standard.
v3:
- Removed bogus test case introduced in v2 (static assertion on sizeof a structure within the definition of the structure).
v2:
- Added additional test cases.
- Added additional validation for parameters to _Static_assert().
- Reworked implementation to avoid impacting struct/union definition handling ( the v1 implementation, which treated _Static_assert() as an NS_TYPEDEF term, had the unfortunate side-effect of leaving an unnamed field with unknown size attached to structure definitions when a static assert was inside a structure definition).
ident-list.h | 1 + parse.c | 45 ++++++++++++++++++++++++++++- validation/static_assert.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 validation/static_assert.c
ident-list.h +1 -0
@@ -16,6 +16,7 @@ IDENT_RESERVED(for);IDENT_RESERVED (while);IDENT_RESERVED (do);IDENT_RESERVED (goto); +IDENT_RESERVED (_Static_assert);/* C typenames. They get marked as reserved when initialized */ IDENT (struct);
parse.c +44 -1
87 lines not on this page · raw message
validation/static_assert.c new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
2.9.3
Christopher Li
maintainerQuoted 16 lines · Lance Richardson
This patch introduces support for the C11
_Static_assert()construct.Per the N1539 draft standard, the syntax changes for this construct include:
declaration: <declaration-specifiers> <init-declarator-list>[opt] ; <static_assert-declaration> struct-declaration: <specifier-qualifier-list> <struct-declarator-list>[opt] ; <static_assert-declaration> static_assert-declaration: _Static_assert ( <constant-expression> , <string-literal> ) ;
Quoted 7 lines
Signed-off-by Lance Richardson <[email protected]>---
v7: Incorporated additional feedback from Christopher Li and
Luc van Oostenryck. Tested via "make check", also redefined Linuxcompiletime_assert()to use_Static_assert()when running sparse (gcc had issues with_Static_assert()in *.s files), no additional warnings were emitted.
This version looks perfect for me.
Luc, do you want to apply the v7 and then I pull from your branch with the other identifier improvements? I can apply it but it might disrupt your branch.
Chris
Quoted 25 lines · Christopher Li
Quoted 16 lines · Lance Richardson
This patch introduces support for the C11
_Static_assert()construct.Per the N1539 draft standard, the syntax changes for this construct include:
declaration: <declaration-specifiers> <init-declarator-list>[opt] ; <static_assert-declaration> struct-declaration: <specifier-qualifier-list> <struct-declarator-list>[opt] ; <static_assert-declaration> static_assert-declaration: _Static_assert ( <constant-expression> , <string-literal> ) ;Quoted 7 lines
Signed-off-by Lance Richardson <[email protected]>---
v7: Incorporated additional feedback from Christopher Li and
Luc van Oostenryck. Tested via "make check", also redefined Linuxcompiletime_assert()to use_Static_assert()when running sparse (gcc had issues with_Static_assert()in *.s files), no additional warnings were emitted.
Quoted 7 lines
This version looks perfect for me.
Signed-off-by Chris Li <[email protected]>Luc, do you want to apply the v7 and then I pull from your branch with the other identifier improvements? I can apply it but it might disrupt your branch.
Sure.
-- Luc