[cfe-dev] Repeated expression in AST

Abramo Bagnara abramo.bagnara at gmail.com
Sun Dec 11 02:13:37 PST 2011


The typescript above shows that clang put *two* references to the same
expr in the AST (one as TypeOfExprType argument and another as
CompoundStmt child).

This leads to shown wrong warning and (I guess) to other problems.

Is it expected?

$ cat bug.c
int f(int);
void h() {
  __typeof(*(int (*)[f(1)]) 0) x;
}


$ _clang -cc1 -ast-print bug.c
bug.c:3:12: warning: expression result unused
  __typeof(*(int (*)[f(1)]) 0) x;
           ^~~~~~~~~~~~~~~~~~
struct __va_list_tag {
    unsigned int gp_offset;
    unsigned int fp_offset;
    void *overflow_arg_area;
    void *reg_save_area;
};
typedef struct __va_list_tag __va_list_tag;
int f(int);
void h() {
    (*(int (*)[f(1)])0);
    typeof (*(int (*)[f(1)])0) x;
}


1 warning generated.


$ _clang -cc1 -ast-dump bug.c
bug.c:3:12: warning: expression result unused
  __typeof(*(int (*)[f(1)]) 0) x;
           ^~~~~~~~~~~~~~~~~~
typedef __int128_t __int128_t;
typedef __uint128_t __uint128_t;
struct __va_list_tag {
    unsigned int gp_offset;
    unsigned int fp_offset;
    void *overflow_arg_area;
    void *reg_save_area;
};
typedef struct __va_list_tag __va_list_tag;
typedef __va_list_tag __builtin_va_list[1];
int f(int);
void h() (CompoundStmt 0x48a5448 <bug.c:2:10, line:4:1>
  (ImplicitCastExpr 0x48a5378 <line:3:11, col:30> 'int *'
<ArrayToPointerDecay>
    (ParenExpr 0x48a5330 <col:11, col:30> 'int [f(1)]':'int [f(1)]' lvalue
      (UnaryOperator 0x48a5310 <col:12, col:29> 'int [f(1)]':'int
[f(1)]' lvalue prefix '*'
        (CStyleCastExpr 0x48a52e8 <col:13, col:29> 'int (*)[f(1)]'
<NullToPointer>
          (IntegerLiteral 0x48a51c0 <col:29> 'int' 0)))))
  (DeclStmt 0x48a5430 <col:3, col:33>
    0x48a53d0 "typeof (*(int (*)[f(1)])0) x"))


1 warning generated.



More information about the cfe-dev mailing list