bit-field notation and k&r function syntax
A message that is not in the archive (sent off-list or not yet received): [email protected]
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;
}Quoted 5 lines · Lance Richardson
I noticed when browsing
parse.cthat function parameters declared using K&R syntax are parsed by callingdeclaration_list(), which seems to have been intended for parsing structure member declarations and accepts bit-field syntax.
Quoted 7 lines
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
Christopher Li
maintainerQuoted 3 lines · Luc Van Oostenryck
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
Quoted 10 lines · Christopher Li
Quoted 3 lines · Luc Van Oostenryck
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 ":" andhandle_bitfield()thing. There are only two caller ofdeclaration_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
Christopher Li
maintainerQuoted 9 lines · Luc Van Oostenryck
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; }
Quoted 5 lines
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
Quoted 17 lines · Christopher Li
Quoted 9 lines · Luc Van Oostenryck
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; }Quoted 5 lines
But this we should warn on this
struct s { register int a; };And currently, we don't.
Quoted 5 lines
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