71 lines · cpp
1// Test without serialization:2// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s \3// RUN: | FileCheck -strict-whitespace %s4//5// Test with serialization:6// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-pch -o %t %s7// RUN: %clang_cc1 -triple x86_64-unknown-unknown -x c++ -include-pch %t -ast-dump-all /dev/null \8// RUN: | FileCheck -strict-whitespace %s9 10void test_type_trait() {11 // An unary type trait.12 enum E {};13 (void) __is_enum(E);14 // A binary type trait.15 (void) __is_same(int ,float);16 // An n-ary type trait.17 (void) __is_constructible(int, int, int, int);18}19 20void test_array_type_trait() {21 // An array type trait.22 (void) __array_rank(int[10][20]);23}24 25void test_expression_trait() {26 // An expression trait.27 (void) __is_lvalue_expr(1);28}29 30void test_unary_expr_or_type_trait() {31 // Some UETTs.32 (void) sizeof(int);33 (void) alignof(int);34 (void) __alignof(int);35}36// CHECK: TranslationUnitDecl {{.*}} <<invalid sloc>> <invalid sloc>{{( <undeserialized declarations>)?}}37// CHECK: |-FunctionDecl {{.*}} <{{.*}}ast-dump-traits.cpp:10:1, line:18:1> line:10:6{{( imported)?}} test_type_trait 'void ()'38// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:24, line:18:1>39// CHECK-NEXT: | |-DeclStmt {{.*}} <line:12:3, col:12>40// CHECK-NEXT: | | `-EnumDecl {{.*}} <col:3, col:11> col:8{{( imported)?}} referenced E41// CHECK-NEXT: | |-CStyleCastExpr {{.*}} <line:13:3, col:21> 'void' <ToVoid>42// CHECK-NEXT: | | `-TypeTraitExpr {{.*}} <col:10, col:21> 'bool' __is_enum43// CHECK-NEXT: | | `-EnumType {{.*}} 'E'44// CHECK-NEXT: | | `-Enum {{.*}} 'E'45// CHECK-NEXT: | |-CStyleCastExpr {{.*}} <line:15:3, col:30> 'void' <ToVoid>46// CHECK-NEXT: | | `-TypeTraitExpr {{.*}} <col:10, col:30> 'bool' __is_same47// CHECK-NEXT: | | |-BuiltinType {{.*}} 'int'48// CHECK-NEXT: | | `-BuiltinType {{.*}} 'float'49// CHECK-NEXT: | `-CStyleCastExpr {{.*}} <line:17:3, col:47> 'void' <ToVoid>50// CHECK-NEXT: | `-TypeTraitExpr {{.*}} <col:10, col:47> 'bool' __is_constructible51// CHECK-NEXT: |-BuiltinType {{.*}} 'int'52// CHECK-NEXT: |-BuiltinType {{.*}} 'int'53// CHECK-NEXT: |-BuiltinType {{.*}} 'int'54// CHECK-NEXT: `-BuiltinType {{.*}} 'int'55// CHECK-NEXT: |-FunctionDecl {{.*}} <line:20:1, line:23:1> line:20:6{{( imported)?}} test_array_type_trait 'void ()'56// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:30, line:23:1>57// CHECK-NEXT: | `-CStyleCastExpr {{.*}} <line:22:3, col:34> 'void' <ToVoid>58// CHECK-NEXT: | `-ArrayTypeTraitExpr {{.*}} <col:10, col:34> '__size_t':'unsigned long' __array_rank59// CHECK-NEXT: |-FunctionDecl {{.*}} <line:25:1, line:28:1> line:25:6{{( imported)?}} test_expression_trait 'void ()'60// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:30, line:28:1>61// CHECK-NEXT: | `-CStyleCastExpr {{.*}} <line:27:3, col:28> 'void' <ToVoid>62// CHECK-NEXT: | `-ExpressionTraitExpr {{.*}} <col:10, col:28> 'bool' __is_lvalue_expr63// CHECK-NEXT: `-FunctionDecl {{.*}} <line:30:1, line:35:1> line:30:6{{( imported)?}} test_unary_expr_or_type_trait 'void ()'64// CHECK-NEXT: `-CompoundStmt {{.*}} <col:38, line:35:1>65// CHECK-NEXT: |-CStyleCastExpr {{.*}} <line:32:3, col:20> 'void' <ToVoid>66// CHECK-NEXT: | `-UnaryExprOrTypeTraitExpr {{.*}} <col:10, col:20> '__size_t':'unsigned long' sizeof 'int'67// CHECK-NEXT: |-CStyleCastExpr {{.*}} <line:33:3, col:21> 'void' <ToVoid>68// CHECK-NEXT: | `-UnaryExprOrTypeTraitExpr {{.*}} <col:10, col:21> '__size_t':'unsigned long' alignof 'int'69// CHECK-NEXT: `-CStyleCastExpr {{.*}} <line:34:3, col:23> 'void' <ToVoid>70// CHECK-NEXT: `-UnaryExprOrTypeTraitExpr {{.*}} <col:10, col:23> '__size_t':'unsigned long' __alignof 'int'71