* Structures from -include are "weak"
@ 2007-07-08 3:32 Pavel Roskin
2007-07-08 5:42 ` Al Viro
0 siblings, 1 reply; 4+ messages in thread
From: Pavel Roskin @ 2007-07-08 3:32 UTC (permalink / raw)
To: linux-sparse
Hello!
I'm trying to use sparse on standalone kernel drivers that use -include
to include compatibility code for slightly older kernels, so that it's
possible to have exactly the same driver sources in the kernel and in
the standalone project.
Support for multiple -include switches has been very helpful, and things
have been working fine for some time, but now I'm seeing massive error
messages about dereferencing members of incomplete structures.
I've been able to reduce the problem to the following test case.
test.h:
struct st {
int len;
};
test.c:
struct st;
int test(struct st *s);
int test(struct st *s)
{
return s->len;
}
Commands to run:
$ sparse -include test.h test.c
test.c:5:10: error: using member 'len' in incomplete struct st
$ gcc -c -include test.h test.c
$
It looks like the definition of struct st is sort of "weak" when it's
read from the header included on the command line, so that the forward
declaration from test.c removes the original definition.
It's also possible to define struct st to something else, and sparse
won't warn about it. But omitting "struct st;" fixes the error, so the
original definition is known to sparse.
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Structures from -include are "weak"
2007-07-08 3:32 Structures from -include are "weak" Pavel Roskin
@ 2007-07-08 5:42 ` Al Viro
2007-07-08 6:06 ` Al Viro
0 siblings, 1 reply; 4+ messages in thread
From: Al Viro @ 2007-07-08 5:42 UTC (permalink / raw)
To: Pavel Roskin; +Cc: linux-sparse
On Sat, Jul 07, 2007 at 11:32:50PM -0400, Pavel Roskin wrote:
> It looks like the definition of struct st is sort of "weak" when it's
> read from the header included on the command line, so that the forward
> declaration from test.c removes the original definition.
>
> It's also possible to define struct st to something else, and sparse
> won't warn about it. But omitting "struct st;" fixes the error, so the
> original definition is known to sparse.
Looks like it gets a scope boundary between those. There is one case
when presense of struct st; changes things: struct st; in
struct st {....};
....
{
struct st;
struct st *p;
...
struct st {....} x;
...
}
will make p a pointer to struct st from that scope. If you omit it,
p will be a pointer to struct st from the outer scope and x will have
a different type. Too late beginning of file scope, perhaps?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Structures from -include are "weak"
2007-07-08 5:42 ` Al Viro
@ 2007-07-08 6:06 ` Al Viro
2007-07-08 6:25 ` Pavel Roskin
0 siblings, 1 reply; 4+ messages in thread
From: Al Viro @ 2007-07-08 6:06 UTC (permalink / raw)
To: Pavel Roskin; +Cc: linux-sparse
On Sun, Jul 08, 2007 at 06:42:18AM +0100, Al Viro wrote:
> {
> struct st;
> struct st *p;
> ...
> struct st {....} x;
> ...
> }
>
> will make p a pointer to struct st from that scope. If you omit it,
> p will be a pointer to struct st from the outer scope and x will have
> a different type. Too late beginning of file scope, perhaps?
Gyah... So it is. We put the stuff from -include into builtin_scope
and start the file scope only in __sparse().
See if adding
int is_outer_scope(struct scope *scope)
{
if (scope == block_scope)
return 0;
if (scope == &builtin_scope && block_scope->next == &builtin_scope)
return 0;
return 1;
}
to scope.c and replacing
sym = lookup_symbol(token->ident, NS_STRUCT);
if (!sym ||
(sym->scope != block_scope &&
(match_op(token->next,';') || match_op(token->next,'{')))) {
with
sym = lookup_symbol(token->ident, NS_STRUCT);
if (!sym ||
(is_outer_scope(sym->scope) &&
(match_op(token->next,';') || match_op(token->next,'{')))) {
in parse.c:struct_union_enum_specifier() would fix all problems of that kind.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Structures from -include are "weak"
2007-07-08 6:06 ` Al Viro
@ 2007-07-08 6:25 ` Pavel Roskin
0 siblings, 0 replies; 4+ messages in thread
From: Pavel Roskin @ 2007-07-08 6:25 UTC (permalink / raw)
To: Al Viro; +Cc: linux-sparse
On Sun, 2007-07-08 at 07:06 +0100, Al Viro wrote:
> Gyah... So it is. We put the stuff from -include into builtin_scope
> and start the file scope only in __sparse().
>
> See if adding
...
> in parse.c:struct_union_enum_specifier() would fix all problems of that kind.
Yes, it's working like a charm! Tested on 3 projects: madwifi, at76_usb
and orinoco_usb - all are fine. Thank you!
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-07-08 6:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-08 3:32 Structures from -include are "weak" Pavel Roskin
2007-07-08 5:42 ` Al Viro
2007-07-08 6:06 ` Al Viro
2007-07-08 6:25 ` Pavel Roskin
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).