[cfe-dev] Unneeded declarations invalidation

Abramo Bagnara abramobagnara at tin.it
Thu Jul 2 01:30:31 PDT 2009


The following typescript show what happens when trying to compile a
simple C source not legal for C99 standard, but accepted and compiled by
gcc.

The C source is a simplified version of a problem seen in linux-2.6.

I'm not sure that in this case an error is better than a proper warning,
but that apart I believe that the choice to invalidate the decl and then
inhibits the generation of code dependending on it is not a good idea
when that is not strictly needed.

>From -ast-dump output you see that the body of f() is horribly mutilated.

Commenting out the two IDecl->setInvalidDecl() in
Sema::FinalizeDeclaratorGroup the -ast-dump output is now complete and
perfect and I don't see any drawback.

Resuming, if codegen is not concerned by this construct (not legal for
C99 but legal for gcc) I'd like to turn it in a proper warning
(otherwise obviously we should leave it a fatal error).

OTOH in both cases, I'd like to avoid to invalidate the declaration and
thus to inhibit ast generation if this is not strictly needed.


$ cat z.c
static __typeof__(struct call_single_queue) per_cpu__call_single_queue;

struct call_single_queue {
  int a;
} s;

int f() {
  typeof(&per_cpu__call_single_queue) b;
  return b->a;
}
$ clang-cc -ast-dump z.c
z.c:1:45: error: variable has incomplete type 'typeof(struct
call_single_queue)'
      (aka 'struct call_single_queue')
static __typeof__(struct call_single_queue) per_cpu__call_single_queue;
                                            ^
z.c:1:26: note: forward declaration of 'struct call_single_queue'
static __typeof__(struct call_single_queue) per_cpu__call_single_queue;
                         ^
typedef char *__builtin_va_list;
struct call_single_queue;
static typeof(struct call_single_queue) per_cpu__call_single_queue;
struct call_single_queue {
    int a;
};
struct call_single_queue s;
int f() (CompoundStmt 0x9b620d8
  (DeclStmt 0x9b83d70
    0x9b83b80 "int b")


2 diagnostics generated.




More information about the cfe-dev mailing list