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: Re: [PATCH 1/3] struct_union_enum_specifier: set MOD_TOPLEVEL if toplevel(sym->scope)
Date: Tue, 18 Feb 2020 11:38:38 +0100	[thread overview]
Message-ID: <20200218103837.GA3466@redhat.com> (raw)
In-Reply-To: <20200217214610.uxbnfh5zooqve4yc@ltop.local>

On 02/17, Luc Van Oostenryck wrote:
>
> On Fri, Feb 14, 2020 at 12:33:20PM +0100, Oleg Nesterov wrote:
> > With this change dissect can know the scope of SYM_STRUCT/UNION/ENUM,
> > see the next patch.
> >
> > Note that MOD_TOPLEVEL can be set even if struct/union/enum type is
> > private and bind_symbol() is not called.
>
> I don't like that very much. For example: why this is needed for
> struct/union/enum and not other types?

Do you mean builtin types like int_ctype? OK, I agree, this is slightly
inconsistent.

> Should it be possible to use the function toplevel() or add and
> helper for it in scope.c?

Well, toplevel() won't work if SYM_STRUCT/etc is anonymous, in this
case bind_symbol() is not called and thus sym->scope = NULL.

Consider

	struct { int m; } x;

	void func(void)
	{
		struct { int m; } x;

	}

we want to report the 2nd struct definition as "local"

   1:8                    def   s :x
   1:14                   def   m :x.m                             int
   1:19                   def   v x                                struct :x
   3:6                    def   f func                             void ( ... )
   5:16  func             def . s :x
   5:22  func             def . m :x.m                             int
   5:27  func             def . v x                                struct :x

so that this spam can be filtered out, but base->scope is NULL in both
cases.

> > IIUC nobody else looks at SYM_STRUCT->ctype.modifiers, "make check"
> > doesn't show any difference.
>
> Yes, it's true and it shouldn't make any difference but still I
> would prefer to not mix symbols and types more than they already are.

OK, will you agree with one-liner below? This should make toplevel() work.

Oleg.

--- a/parse.c
+++ b/parse.c
@@ -772,6 +772,7 @@ static struct token *struct_union_enum_specifier(enum type type,
 	}
 
 	sym = alloc_symbol(token->pos, type);
+	sym->scope = block_scope;
 	token = parse(token->next, sym);
 	ctx->ctype.base_type = sym;
 	token =  expect(token, '}', "at end of specifier");

  reply	other threads:[~2020-02-18 10:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-14 11:33 [PATCH 1/3] struct_union_enum_specifier: set MOD_TOPLEVEL if toplevel(sym->scope) Oleg Nesterov
2020-02-14 11:33 ` [PATCH 2/3] dissect: fix sym_is_local(SYM_STRUCT/UNION/ENUM) Oleg Nesterov
2020-02-14 11:34 ` [PATCH 3/3] dissect: enforce MOD_TOPLEVEL if SYM_STRUCT was not defined Oleg Nesterov
2020-02-17 21:46 ` [PATCH 1/3] struct_union_enum_specifier: set MOD_TOPLEVEL if toplevel(sym->scope) Luc Van Oostenryck
2020-02-18 10:38   ` Oleg Nesterov [this message]
2020-02-18 15:59     ` Luc Van Oostenryck

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=20200218103837.GA3466@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).