From: Bart Van Assche <bvanassche@acm.org>
To: linux-sparse@vger.kernel.org
Cc: Bart Van Assche <bvanassche@acm.org>,
Dmitry Ilvokhin <d@ilvokhin.com>,
Dan Carpenter <error27@gmail.com>
Subject: [PATCH 18/20] parse: Accept an empty attribute argument list
Date: Mon, 19 Oct 2026 10:56:31 -0700 [thread overview]
Message-ID: <20261019175633.415493-19-bvanassche@acm.org> (raw)
In-Reply-To: <20261019175633.415493-1-bvanassche@acm.org>
From: Dmitry Ilvokhin <d@ilvokhin.com>
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/aiJi0WcYE8FZt-jO@stanley.mountain/
Reported-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Dmitry Ilvokhin <d@ilvokhin.com>
Tested-by: Dan Carpenter <error27@gmail.com>
[ bvanassche: added "parse" prefix to the patch subject ]
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
parse.c | 17 +++++++++++++----
validation/attribute-nonnull-empty.c | 12 ++++++++++++
2 files changed, 25 insertions(+), 4 deletions(-)
create mode 100644 validation/attribute-nonnull-empty.c
diff --git a/parse.c b/parse.c
index 0e3e384550c5..1a889ccb6a90 100644
--- a/parse.c
+++ b/parse.c
@@ -1106,8 +1106,13 @@ static struct token *autotype_specifier(struct token *token, struct symbol *sym,
static struct token *ignore_attribute(struct token *token, struct symbol *attr, struct decl_state *ctx)
{
struct expression *expr = NULL;
- if (match_op(token, '('))
- token = parens_expression(token, &expr, "in attribute");
+ if (match_op(token, '(')) {
+ /* Accept an empty argument list, e.g. __attribute__((nonnull())) */
+ if (match_op(token->next, ')'))
+ token = token->next->next;
+ else
+ token = parens_expression(token, &expr, "in attribute");
+ }
return token;
}
@@ -1362,8 +1367,12 @@ static struct token *recover_unknown_attribute(struct token *token)
if (Wunknown_attribute)
warning(token->pos, "unknown attribute '%s'", show_ident(token->ident));
token = token->next;
- if (match_op(token, '('))
- token = parens_expression(token, &expr, "in attribute");
+ if (match_op(token, '(')) {
+ if (match_op(token->next, ')'))
+ token = token->next->next;
+ else
+ token = parens_expression(token, &expr, "in attribute");
+ }
return token;
}
diff --git a/validation/attribute-nonnull-empty.c b/validation/attribute-nonnull-empty.c
new file mode 100644
index 000000000000..c4021f61db0e
--- /dev/null
+++ b/validation/attribute-nonnull-empty.c
@@ -0,0 +1,12 @@
+/*
+ * An empty attribute argument list, like __attribute__((nonnull())), is
+ * accepted by GCC and Clang (equivalent to the bare __attribute__((nonnull)))
+ * and must be parsed by sparse too.
+ */
+extern void *bare (void *d, const void *s) __attribute__((nonnull));
+extern void *empty(void *d, const void *s) __attribute__((nonnull()));
+extern void *args (void *d, const void *s) __attribute__((nonnull(1, 2)));
+
+/*
+ * check-name: attribute with empty argument list
+ */
next prev parent reply other threads:[~2026-10-19 17:56 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 17:56 [PATCH 00/20] Sanitizer fixes, LLVM updates, and CI workflow Bart Van Assche
2026-10-19 17:56 ` [PATCH 01/20] doc: Update maintainer and mirror information Bart Van Assche
2026-10-19 17:56 ` [PATCH 02/20] ptrlist: Guard against null list in ptrlist operations Bart Van Assche
2026-10-21 13:02 ` Dmitry Ilvokhin
2026-10-19 17:56 ` [PATCH 03/20] bits: Guard against out-of-bounds bit shifts in bitmask helpers Bart Van Assche
2026-10-21 13:22 ` Dmitry Ilvokhin
2026-10-19 17:56 ` [PATCH 04/20] storage: Free hash table entries when freeing storage Bart Van Assche
2026-10-21 13:50 ` Dmitry Ilvokhin
2026-10-21 16:21 ` Bart Van Assche
2026-10-22 11:39 ` Dmitry Ilvokhin
2026-10-19 17:56 ` [PATCH 05/20] builtin: Bound argument array iteration in declare_builtin() Bart Van Assche
2026-10-21 13:54 ` Dmitry Ilvokhin
2026-10-19 17:56 ` [PATCH 06/20] c2xml: Use an unsigned shift in examine_modifiers() Bart Van Assche
2026-10-19 17:56 ` [PATCH 07/20] parse: Avoid incrementing rank on invalid long real specifiers Bart Van Assche
2026-10-19 17:56 ` [PATCH 08/20] pre-process: Avoid zero-length VLAs for parameterless macros Bart Van Assche
2026-10-19 17:56 ` [PATCH 09/20] pre-process: Avoid reading token->string on non-string tokens Bart Van Assche
2026-10-19 17:56 ` [PATCH 10/20] target: Avoid signed overflow in bit and byte conversion helpers Bart Van Assche
2026-10-19 17:56 ` [PATCH 11/20] evaluate: Use bitmask helpers in evaluate_ptr_add() Bart Van Assche
2026-10-19 17:56 ` [PATCH 12/20] linearize: Use bits_mask() in linearize_bitfield_insert() Bart Van Assche
2026-10-19 17:56 ` [PATCH 13/20] expand: Avoid undefined shifts and signed overflow in constant folding Bart Van Assche
2026-10-19 17:56 ` [PATCH 14/20] simplify: Avoid undefined shifts and signed overflow in simplification Bart Van Assche
2026-10-19 17:56 ` [PATCH 15/20] sparsec: Emit object files directly with llc -filetype=obj Bart Van Assche
2026-10-19 17:56 ` [PATCH 16/20] llvm: Stop calling LLVMConstGEP2() for string literals Bart Van Assche
2026-10-19 17:56 ` [PATCH 17/20] llvm: Free leaked allocations and LLVM objects Bart Van Assche
2026-10-19 17:56 ` Bart Van Assche [this message]
2026-10-19 17:56 ` [PATCH 19/20] llvm: Use explicit LLVMContextRef instead of global context Bart Van Assche
2026-10-19 17:56 ` [PATCH 20/20] ci: Add a GitHub Actions workflow and CI scripts Bart Van Assche
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261019175633.415493-19-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=d@ilvokhin.com \
--cc=error27@gmail.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.