Skip to contentSkip to conversation

bit-field notation and k&r function syntax

DISCUSSION Lance Richardson 3 participants 6 messages May 3, 2017 – May 4, 2017 1 message not in the archive Sparse checker

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

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;
}
#2 lore raw
Quoted 5 lines · Lance Richardson

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.

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

maintainer
#3 lore raw
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 ":" and handle_bitfield() thing. There are only two caller of declaration_list() so that should fix it.

Chris

#4 lore raw
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 ":" 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

maintainer
#5 lore raw
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.

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

#6 lore raw
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