[cfe-dev] AST is alterated for valid code?

Abramo Bagnara abramo.bagnara at gmail.com
Tue Jul 3 03:14:53 PDT 2012


It seems that clang alters a perfectly valid AST adding a bogus
__builtin_trap.

Am I wrong if I say that a strong invariant for clang is that AST of
valid code should always be conformant with original source?

The test is taken from g++ testsuite:

$ cat sizeof6.C
// { dg-do compile }
// Contributed by Giovanni Bajo <giovannibajo at gcc dot gnu dot org>
// PR c++/13683: bogus warning about passing non-PODs through ellipsis

struct B {};
struct NonPOD : B {};

struct A
{
  static int check(...);
  static NonPOD GetNonPOD(void);
  enum { value = sizeof(A::check(A::GetNonPOD())) };
};
$ ~/llvm_trunk/Release+Asserts/bin/clang++ -cc1 -ast-dump sizeof6.C
typedef __int128 __int128_t;
typedef unsigned __int128 __uint128_t;
typedef __va_list_tag __builtin_va_list[1];
struct B {
    struct B;
    inline void ~B() throw();
};
struct NonPOD :  B {
    struct NonPOD;
    inline void ~NonPOD() throw();
};
struct A {
    struct A;
    static int check(...);
    static NonPOD GetNonPOD();
    enum  {
        value = (ImplicitCastExpr 0x2d8adb0 <sizeof6.C:12:18, col:49>
'unsigned int' <IntegralCast>
  (UnaryExprOrTypeTraitExpr 0x2d8ad40 <col:18, col:49> 'unsigned long'
sizeof
    (ParenExpr 0x2d8ad20 <col:24, col:49> 'int'
      (CallExpr 0x2d8ab10 <col:25, col:48> 'int'
        (ImplicitCastExpr 0x2d8aaf8 <col:25, col:28> 'int (*)(...)'
<FunctionToPointerDecay>
          (DeclRefExpr 0x2d8a778 <col:25, col:28> 'int (...)' lvalue
CXXMethod 0x2d8a460 'check' 'int (...)'))
        (BinaryOperator 0x2d8acf8 <col:34, col:47> 'struct NonPOD' ','
          (CallExpr 0x2d8acd0 <col:34, col:47> 'void'
            (ImplicitCastExpr 0x2d8acb8 <col:34> 'void (*)(void)
__attribute__((noreturn))' <FunctionToPointerDecay>
              (DeclRefExpr 0x2d8ac68 <col:34> 'void (void)
__attribute__((noreturn))' lvalue Function 0x2d8ab70 '__builtin_trap'
'void (void) __attribute__((noreturn))')))
          (CallExpr 0x2d8a860 <col:34, col:47> 'struct NonPOD'
            (ImplicitCastExpr 0x2d8a848 <col:34, col:37> 'struct NonPOD
(*)(void)' <FunctionToPointerDecay>
              (DeclRefExpr 0x2d8a7e8 <col:34, col:37> 'struct NonPOD
(void)' lvalue CXXMethod 0x2d8a5c0 'GetNonPOD' 'struct NonPOD
(void)'))))))))

    };
};
void __builtin_trap() __attribute__((nothrow));



More information about the cfe-dev mailing list