* bit-field notation and k&r function syntax [not found] <1231012108.4484627.1493830970281.JavaMail.zimbra@redhat.com> @ 2017-05-03 17:10 ` Lance Richardson 2017-05-03 23:07 ` Luc Van Oostenryck 0 siblings, 1 reply; 6+ messages in thread From: Lance Richardson @ 2017-05-03 17:10 UTC (permalink / raw) To: Linux-Sparse I noticed when browsing parse.c that function parameters declared using K&R syntax are parsed by calling declaration_list(), which seems to have been intended for parsing structure member declarations and accepts bit-field syntax. So e.g. this is (incorrectly) accepted by sparse: static int foo(b) int b: 4; { return 0; } ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: bit-field notation and k&r function syntax 2017-05-03 17:10 ` bit-field notation and k&r function syntax Lance Richardson @ 2017-05-03 23:07 ` Luc Van Oostenryck 2017-05-04 1:50 ` Christopher Li 0 siblings, 1 reply; 6+ messages in thread From: Luc Van Oostenryck @ 2017-05-03 23:07 UTC (permalink / raw) To: Lance Richardson; +Cc: Linux-Sparse On Wed, May 03, 2017 at 01:10:12PM -0400, Lance Richardson wrote: > I noticed when browsing parse.c that function parameters declared > using K&R syntax are parsed by calling declaration_list(), which > seems to have been intended for parsing structure member declarations > and accepts bit-field syntax. > > So e.g. this is (incorrectly) accepted by sparse: > > static int foo(b) > int b: 4; > { > return 0; > } Hmmm yes. What's sparse use 'declaration_list()' for is not what correspond to the standard's 'declaration-list' but is indeed for something that should be reserved to structs. Nice catch. -- Luc ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: bit-field notation and k&r function syntax 2017-05-03 23:07 ` Luc Van Oostenryck @ 2017-05-04 1:50 ` Christopher Li 2017-05-04 2:14 ` Luc Van Oostenryck 0 siblings, 1 reply; 6+ messages in thread From: Christopher Li @ 2017-05-04 1:50 UTC (permalink / raw) To: Luc Van Oostenryck; +Cc: Lance Richardson, Linux-Sparse On Wed, May 3, 2017 at 7:07 PM, Luc Van Oostenryck <luc.vanoostenryck@gmail.com> wrote: > What's sparse use 'declaration_list()' for is not what correspond > to the standard's 'declaration-list' but is indeed for something > that should be reserved to structs. I think declaration_list() can add one argument "is_struct" to indicate parse for struct or not. Only in struct mode we do the ":" and handle_bitfield() thing. There are only two caller of declaration_list() so that should fix it. Chris ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: bit-field notation and k&r function syntax 2017-05-04 1:50 ` Christopher Li @ 2017-05-04 2:14 ` Luc Van Oostenryck 2017-05-04 3:20 ` Christopher Li 0 siblings, 1 reply; 6+ messages in thread From: Luc Van Oostenryck @ 2017-05-04 2:14 UTC (permalink / raw) To: Christopher Li; +Cc: Lance Richardson, Linux-Sparse On Wed, May 03, 2017 at 09:50:14PM -0400, Christopher Li wrote: > On Wed, May 3, 2017 at 7:07 PM, Luc Van Oostenryck > <luc.vanoostenryck@gmail.com> wrote: > > What's sparse use 'declaration_list()' for is not what correspond > > to the standard's 'declaration-list' but is indeed for something > > that should be reserved to structs. > > I think declaration_list() can add one argument "is_struct" to > indicate parse for struct or not. > Only in struct mode we do the ":" and handle_bitfield() thing. > There are only two caller of declaration_list() so that should fix it. Yes, but there are a few details we need to look at. For example, this should be supported (GCC does) int foo(a) register int a; { return a; } But this we should warn on this struct s { register int a; }; And currently, we don't. -- Luc ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: bit-field notation and k&r function syntax 2017-05-04 2:14 ` Luc Van Oostenryck @ 2017-05-04 3:20 ` Christopher Li 2017-05-04 15:07 ` Luc Van Oostenryck 0 siblings, 1 reply; 6+ messages in thread From: Christopher Li @ 2017-05-04 3:20 UTC (permalink / raw) To: Luc Van Oostenryck; +Cc: Lance Richardson, Linux-Sparse On Wed, May 3, 2017 at 10:14 PM, Luc Van Oostenryck <luc.vanoostenryck@gmail.com> wrote: > > Yes, but there are a few details we need to look at. > For example, this should be supported (GCC does) > int foo(a) > register int a; > { > return a; > } > > But this we should warn on this > struct s { > register int a; > }; > And currently, we don't. You are right. If we really want to fix that, we could add some field into "struct decl_state" to indicate we are in the struct mode, some storage specifier does not apply. Can be a separate patch. Chris ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: bit-field notation and k&r function syntax 2017-05-04 3:20 ` Christopher Li @ 2017-05-04 15:07 ` Luc Van Oostenryck 0 siblings, 0 replies; 6+ messages in thread From: Luc Van Oostenryck @ 2017-05-04 15:07 UTC (permalink / raw) To: Christopher Li; +Cc: Lance Richardson, Linux-Sparse On Wed, May 03, 2017 at 11:20:24PM -0400, Christopher Li wrote: > On Wed, May 3, 2017 at 10:14 PM, Luc Van Oostenryck > <luc.vanoostenryck@gmail.com> wrote: > > > > Yes, but there are a few details we need to look at. > > For example, this should be supported (GCC does) > > int foo(a) > > register int a; > > { > > return a; > > } > > > > But this we should warn on this > > struct s { > > register int a; > > }; > > And currently, we don't. > > You are right. If we really want to fix that, we could add some field into > "struct decl_state" to indicate we are in the struct mode, some storage > specifier does not apply. > > Can be a separate patch. It's not that I care much about pre-ANSI syntax but this 'register' allowed inside a struct really bugs me. I'll look for a patchs in the coming days. -- Luc ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-05-04 15:07 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1231012108.4484627.1493830970281.JavaMail.zimbra@redhat.com>
2017-05-03 17:10 ` bit-field notation and k&r function syntax Lance Richardson
2017-05-03 23:07 ` Luc Van Oostenryck
2017-05-04 1:50 ` Christopher Li
2017-05-04 2:14 ` Luc Van Oostenryck
2017-05-04 3:20 ` Christopher Li
2017-05-04 15:07 ` Luc Van Oostenryck
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).