Re: [PATCH] accept an empty attribute argument list

Dan Carpenter <[email protected]> Fri, 5 Jun 2026 18:26:44 +0300
Newsgroups org.kernel.vger.linux-sparse
Message-ID <[email protected]>
On Fri, Jun 05, 2026 at 11:30:45AM +0000, Dmitry Ilvokhin wrote:
> GCC and clang accept an empty argument list for attributes, e.g.
> __attribute__((nonnull())), and treat it the same as the bare
> __attribute__((nonnull)). sparse instead rejects it with
> "an expression is expected before ')'".
> 
> ignore_attribute() and recover_unknown_attribute() consume the optional
> argument list with parens_expression(), which requires a non-empty
> expression, so an empty () is rejected. The bare form is fine because it
> takes no parentheses and skips that path.
> 
> This turned up in the Linux kernel: the cleanup.h guard macros expand
> __nonnull_args() to __attribute__((__nonnull__())).
> 
>   https://lore.kernel.org/all/[email protected]/
> 
> Reported-by: Dan Carpenter <[email protected]>
> Signed-off-by: Dmitry Ilvokhin <[email protected]>
> ---
>  parse.c                              | 17 +++++++++++++----
>  validation/attribute-nonnull-empty.c | 12 ++++++++++++
>  2 files changed, 25 insertions(+), 4 deletions(-)
>  create mode 100644 validation/attribute-nonnull-empty.c

Thanks so much!

Tested-by: Dan Carpenter <[email protected]>

regards,
dan carpenter