linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Roskin <proski@gnu.org>
To: linux-sparse@vger.kernel.org
Subject: Structures from -include are "weak"
Date: Sat, 07 Jul 2007 23:32:50 -0400	[thread overview]
Message-ID: <1183865570.12651.18.camel@gx> (raw)

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

             reply	other threads:[~2007-07-08  3:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-08  3:32 Pavel Roskin [this message]
2007-07-08  5:42 ` Structures from -include are "weak" Al Viro
2007-07-08  6:06   ` Al Viro
2007-07-08  6:25     ` Pavel Roskin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1183865570.12651.18.camel@gx \
    --to=proski@gnu.org \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).