Skip to contentSkip to conversation

declaration specifiers wooziness

DISCUSSION Alexey Dobriyan 4 participants 11 messages Jun 27, 2007 Sparse checker

lore
Share & tools
lore
#0 lore raw

sparse silently accepts some peculiar combinations of declaration specifiers:

"typedef extern;" passes.

"void char a;" errors about void declaration, however, "extern void char a;" passes. Hey, "extern void a;" passes!

"char short a;" passes too. Ditto for "char float a;" and "char long a".

"typedef inline a;" passes.

Not sure how many different bugs there are here, though...

#1 lore raw
Quoted 8 lines · Alexey Dobriyan

sparse silently accepts some peculiar combinations of declaration specifiers:

"typedef extern;" passes.

"void char a;" errors about void declaration, however, "extern void char a;" passes. Hey, "extern void a;" passes!

Quoted 6 lines

"char short a;" passes too. Ditto for "char float a;" and "char long a".

"typedef inline a;" passes.

Not sure how many different bugs there are here, though...

Several more:

int;
void;
int *;
void *;
static;
extern;
volatile;
static foo;
extern foo;
volatile foo;
int volatile;

- Josh Triplett

#2 lore raw

Alex, Josh,

Quoted 3 lines · Alexey Dobriyan
Quoted 2 lines

sparse silently accepts some peculiar combinations of declaration specifiers:

These are all permitted by the syntax of C.

6.7 Declarations, the init-declarator-list is optional.

Quoted 1 line
Quoted 1 line

"typedef extern;" passes.

...

Quoted 1 line
Quoted 1 line

Not sure how many different bugs there are here, though...

Sparse might flag the usage as suspicious, but it is not a bug.

Quoted 1 line

Several more:

The syntax permits:

signed unsigned short long double int;

Quoted 21 lines

int;
void;
int *;
void *;
static;
extern;
volatile;
static foo;
extern foo;
volatile foo;
int volatile;

- Josh Triplett

-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 3 lines
Derek M. Jones                              tel: +44 (0) 1252 520 667
Knowledge Software Ltd                      mailto:[email protected]
Applications Standards Conformance Testing    http://www.knosof.co.uk
#3 lore raw
Quoted 3 lines · Derek M Jones

The syntax permits:

signed unsigned short long double int;

Please, read 6.7.2(2).

#4 lore raw
Quoted 6 lines · Alexey Dobriyan
Quoted 3 lines · Derek M Jones

The syntax permits:

signed unsigned short long double int;

Please, read 6.7.2(2).

Semantic spoil sport.

Signature · 3 lines
Derek M. Jones                              tel: +44 (0) 1252 520 667
Knowledge Software Ltd                      mailto:[email protected]
Applications Standards Conformance Testing    http://www.knosof.co.uk
#8 lore raw
In reply to Derek M Jones
Quoted 9 lines · Derek M Jones

Alex, Josh,

Quoted 3 lines · Alexey Dobriyan
Quoted 2 lines

sparse silently accepts some peculiar combinations of declaration specifiers:

These are all permitted by the syntax of C.

6.7 Declarations, the init-declarator-list is optional.

Huh; interesting. That explains "int volatile;" as well; it doesn't parse as an attempt to declare an integer named volatile, but as a declaration with no variable.

Quoted 5 lines
Quoted 1 line
Quoted 1 line

"typedef extern;" passes.

...

Quoted 1 line
Quoted 1 line

Not sure how many different bugs there are here, though...

Sparse might flag the usage as suspicious, but it is not a bug.

Probably not worth the trouble of flagging.

Quoted 5 lines
Quoted 1 line

Several more:

The syntax permits:

signed unsigned short long double int;

I would hope it does not permit "double int".

Sparse will in fact spew errors about *that* syntax:
/dev/stdin:1:8: error: You cannot have both signed and unsigned modifiers. /dev/stdin:1:17: error: You cannot have both signed and unsigned modifiers. /dev/stdin:1:23: error: You cannot have both long and short modifiers. /dev/stdin:1:23: error: You cannot have both signed and unsigned modifiers. /dev/stdin:1:28: error: modifier [signed] [unsigned] is invalid in this context /dev/stdin:1:28: error: You cannot have both signed and unsigned modifiers. /dev/stdin:1:35: error: Trying to use reserved word 'int' as identifier

- Josh Triplett

#10 lore raw
In reply to Derek M Jones
Quoted 3 lines · Derek M Jones

These are all permitted by the syntax of C.

6.7 Declarations, the init-declarator-list is optional.

See 6.7[2]; the things like

	int ;

violate the constraint.

Quoted 5 lines
Quoted 1 line
Quoted 1 line

"typedef extern;" passes.

...

Quoted 1 line
Quoted 1 line

Not sure how many different bugs there are here, though...

Sparse might flag the usage as suspicious, but it is not a bug.

See 6.7.1[2]; no more than one storage class specifier in a declaration.

Quoted 5 lines
Quoted 1 line

Several more:

The syntax permits:

signed unsigned short long double int;

See 6.7.2[2]; the set you've given is not in the list given there.

#9 lore raw
In reply to Josh Triplett
Quoted 7 lines · Josh Triplett
Quoted 6 lines · Derek M Jones

Alex, Josh,

Quoted 3 lines · Alexey Dobriyan
Quoted 2 lines

sparse silently accepts some peculiar combinations of declaration specifiers:

Quoted 7 lines
Quoted 3 lines

These are all permitted by the syntax of C.

6.7 Declarations, the init-declarator-list is optional.

Huh; interesting. That explains "int volatile;" as well; it doesn't parse as an attempt to declare an integer named volatile, but as a declaration with no variable.

It is optional for structs, unions and enums.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line

"typedef extern;" passes.

...

Quoted 1 line
Quoted 1 line

Not sure how many different bugs there are here, though...

Sparse might flag the usage as suspicious, but it is not a bug.

Probably not worth the trouble of flagging.

... only because any compiler is going to throw up on it anyway.

#5 lore raw
In reply to Derek M Jones

All,

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

The syntax permits:

signed unsigned short long double int;

Please, read 6.7.2(2).

Semantic spoil sport.

The point I did not mention before sending the email was the extent to which Sparse needs to check constructs that are constraint violations and thus assumed to be checked by the compiler.

Ok, it is possible to get weird looking stuff through sparse without complaint, but is it worth spending time flagging it?

Surely time should be concentrated on flagging suspicious constructs that are valid C and not in correctly handling obscure corners of the language.

Signature · 3 lines
Derek M. Jones                              tel: +44 (0) 1252 520 667
Knowledge Software Ltd                      mailto:[email protected]
Applications Standards Conformance Testing    http://www.knosof.co.uk
#6 lore raw
Quoted 15 lines · Derek M Jones

All,

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

The syntax permits:

signed unsigned short long double int;

Please, read 6.7.2(2).

Semantic spoil sport.

The point I did not mention before sending the email was the extent to which Sparse needs to check constructs that are constraint violations and thus assumed to be checked by the compiler.

Quoted 6 lines

Ok, it is possible to get weird looking stuff through sparse without complaint, but is it worth spending time flagging it?

Surely time should be concentrated on flagging suspicious constructs that are valid C and not in correctly handling obscure corners of the language.

Ideally, I would like Sparse to provide a self-contained set of warnings, even those potentially redundant with a compiler. However, I agree that in general Sparse should give priority to issues that a compiler will not already flag.

- Josh Triplett

#7 lore raw
In reply to Derek M Jones
Quoted 7 lines · Derek M Jones

The point I did not mention before sending the email was the extent to which Sparse needs to check constructs that are constraint violations and thus assumed to be checked by the compiler.

Ok, it is possible to get weird looking stuff through sparse without complaint, but is it worth spending time flagging it?

Yes, if they turn into problems later on. One practical reason is that we are short on MOD_... bits; carrying MOD_LONG et.al. might be a bad idea - we might want to choose the right integer type (as in, the right struct symbol out of small set) and be done with those; conversions can be done that way just fine, we don't need to look at MOD_LONG et.al. for those.