linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Alexey Gladkov <gladkov.alexey@gmail.com>, linux-sparse@vger.kernel.org
Subject: [PATCH] dissect: change do_symbol(SYM_FN) to check base_type->stmt != NULL
Date: Fri, 7 Feb 2020 11:32:07 +0100	[thread overview]
Message-ID: <20200207103207.GA16991@redhat.com> (raw)

examine_fn_arguments() silently degenerates function arguments into
pointers but dissect doesn't do evaluate_symbol_list(), that is why
do_sym_list(type->arguments) can report the bogus definitions.

Test case:

	void extf(int MUST_NOT_BE_REPORTED);
	typedef void (fptr_t)(int MUST_NOT_BE_REPORTED);

	void func1(fptr_t fptr) {}
	void func2(typeof(extf) fptr) {}
	void func3(void) { typeof(extf) fptr; };
	void func4(void (fptr)(int MUST_NOT_BE_REPORTED)) {}

without this patch:

	4:6                    def  func1                            void ( ... )
	4:12  func1            def  fptr                             void ( ... )
	2:23  fptr             def  MUST_NOT_BE_REPORTED             int
	5:6                    def  func2                            void ( ... )
	5:19  func2            ---  extf                             void ( ... )
	5:12  func2            def  fptr                             void ( ... )
	1:11  fptr             def  MUST_NOT_BE_REPORTED             int
	6:6                    def  func3                            void ( ... )
	6:27  func3            ---  extf                             void ( ... )
	6:33  func3            def  fptr                             void ( ... )
	1:11  fptr             def  MUST_NOT_BE_REPORTED             int
	7:6                    def  func4                            void ( ... )
	7:12  func4            def  fptr                             void ( ... )
	7:24  fptr             def  MUST_NOT_BE_REPORTED             int

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 dissect.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/dissect.c b/dissect.c
index 54e11d2..b48cd85 100644
--- a/dissect.c
+++ b/dissect.c
@@ -589,6 +589,7 @@ static inline struct symbol *do_symbol(struct symbol *sym)
 {
 	struct symbol *type = base_type(sym);
 	struct symbol *dctx = dissect_ctx;
+	struct statement *stmt;
 
 	reporter->r_symdef(sym);
 
@@ -603,12 +604,22 @@ static inline struct symbol *do_symbol(struct symbol *sym)
 		dissect_ctx = dctx;
 
 	break; case SYM_FN:
+		stmt = sym->ctype.modifiers & MOD_INLINE
+			? type->inline_stmt
+			: type->stmt;
+		if (!stmt)
+			break;
+
+		if (dctx)
+			sparse_error(dctx->pos,
+				"dissect_ctx change %.*s -> %s",
+				dctx->ident->len, dctx->ident->name,
+				show_ident(sym->ident));
+
 		dissect_ctx = sym;
 		return_type = base_type(type);
 		do_sym_list(type->arguments);
-		do_statement(U_VOID, sym->ctype.modifiers & MOD_INLINE
-					? type->inline_stmt
-					: type->stmt);
+		do_statement(U_VOID, stmt);
 		dissect_ctx = dctx;
 		return_type = NULL;
 	}
-- 
2.5.0

                 reply	other threads:[~2020-02-07 10:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200207103207.GA16991@redhat.com \
    --to=oleg@redhat.com \
    --cc=gladkov.alexey@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).