aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeoff Johnstone <geoff.johnstone@googlemail.com>2008-04-05 02:59:06 -0700
committerJosh Triplett <josh@freedesktop.org>2008-04-05 02:59:06 -0700
commit08431f18af58bb612976185000a465bf8168582b (patch)
tree8f95aecca93189da98ac83b5282b746b8b909bc8
parent27be02d4055500ab7a3f8607f9daef044375b155 (diff)
downloadsparse-08431f18af58bb612976185000a465bf8168582b.tar.gz
sparse-08431f18af58bb612976185000a465bf8168582b.tar.xz
sparse-08431f18af58bb612976185000a465bf8168582b.zip
Fix type mismatches with incomplete types
If I put the following in a public header: struct foo; typedef struct foo *Foo; void func (Foo f); and the definition of struct foo in a private header: struct foo { int bar; } then I get a sparse warning (different base type for argument 1) when I compile the implementation file: #include "public.h" #include "private.h" void func (Foo f) { ... } i.e. sparse doesn't realise that the incomplete structure definition in the function prototype refers to the same type as the complete structure definition in the function definition. *I think* that the patch fixes this - it silences the error - but I don't know enough about sparse to know whether it's correct (or whether it silences other legitimate errors, for example). Signed-off-by: Geoff Johnstone <geoff.johnstone@googlemail.com>
-rw-r--r--evaluate.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/evaluate.c b/evaluate.c
index 4928584..2a126dd 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -697,8 +697,12 @@ const char *type_difference(struct ctype *c1, struct ctype *c2,
type);
return "bad types";
case SYM_RESTRICT:
+ return "different base types";
case SYM_UNION:
case SYM_STRUCT:
+ /* allow definition of incomplete structs and unions */
+ if (t1->ident == t2->ident)
+ return NULL;
return "different base types";
case SYM_ARRAY:
/* XXX: we ought to compare sizes */