xref: /aosp_15_r20/external/clang/test/PCH/exprs.h (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // Header for PCH test exprs.c
2*67e74705SXin Li 
3*67e74705SXin Li // DeclRefExpr
4*67e74705SXin Li int i = 17;
5*67e74705SXin Li enum Enum { Enumerator = 18 };
6*67e74705SXin Li typedef typeof(i) int_decl_ref;
7*67e74705SXin Li typedef typeof(Enumerator) enum_decl_ref;
8*67e74705SXin Li 
9*67e74705SXin Li // IntegerLiteral
10*67e74705SXin Li typedef typeof(17) integer_literal;
11*67e74705SXin Li typedef typeof(17l) long_literal;
12*67e74705SXin Li 
13*67e74705SXin Li // FloatingLiteral and ParenExpr
14*67e74705SXin Li typedef typeof((42.5)) floating_literal;
15*67e74705SXin Li 
16*67e74705SXin Li // ImaginaryLiteral
17*67e74705SXin Li typedef typeof(17.0i) imaginary_literal;
18*67e74705SXin Li 
19*67e74705SXin Li // StringLiteral
20*67e74705SXin Li const char *hello = "Hello" "PCH" "World";
21*67e74705SXin Li 
22*67e74705SXin Li // CharacterLiteral
23*67e74705SXin Li typedef typeof('a') char_literal;
24*67e74705SXin Li 
25*67e74705SXin Li // UnaryOperator
26*67e74705SXin Li typedef typeof(-Enumerator) negate_enum;
27*67e74705SXin Li 
28*67e74705SXin Li // OffsetOfExpr
29*67e74705SXin Li struct X {
30*67e74705SXin Li   int member;
31*67e74705SXin Li };
32*67e74705SXin Li struct Y {
33*67e74705SXin Li   struct X array[5];
34*67e74705SXin Li };
35*67e74705SXin Li struct Z {
36*67e74705SXin Li   struct Y y;
37*67e74705SXin Li };
38*67e74705SXin Li typedef typeof(__builtin_offsetof(struct Z, y.array[1 + 2].member))
39*67e74705SXin Li   offsetof_type;
40*67e74705SXin Li 
41*67e74705SXin Li // UnaryExprOrTypeTraitExpr
42*67e74705SXin Li typedef typeof(sizeof(int)) typeof_sizeof;
43*67e74705SXin Li typedef typeof(sizeof(Enumerator)) typeof_sizeof2;
44*67e74705SXin Li 
45*67e74705SXin Li // ArraySubscriptExpr
46*67e74705SXin Li extern double values[];
47*67e74705SXin Li typedef typeof(values[2]) array_subscript;
48*67e74705SXin Li 
49*67e74705SXin Li // CallExpr
50*67e74705SXin Li double dplus(double x, double y);
51*67e74705SXin Li double d0, d1;
52*67e74705SXin Li typedef typeof((&dplus)(d0, d1)) call_returning_double;
53*67e74705SXin Li 
54*67e74705SXin Li // MemberExpr
55*67e74705SXin Li struct S {
56*67e74705SXin Li   double x;
57*67e74705SXin Li };
58*67e74705SXin Li typedef typeof(((struct S*)0)->x) member_ref_double;
59*67e74705SXin Li 
60*67e74705SXin Li // BinaryOperator
61*67e74705SXin Li typedef typeof(i + Enumerator) add_result;
62*67e74705SXin Li 
63*67e74705SXin Li // CompoundAssignOperator
64*67e74705SXin Li typedef typeof(i += Enumerator) addeq_result;
65*67e74705SXin Li 
66*67e74705SXin Li // ConditionalOperator
67*67e74705SXin Li typedef typeof(i? : d0) conditional_operator;
68*67e74705SXin Li 
69*67e74705SXin Li // CStyleCastExpr
70*67e74705SXin Li typedef typeof((void *)0) void_ptr;
71*67e74705SXin Li 
72*67e74705SXin Li // CompoundLiteral
73*67e74705SXin Li typedef typeof((struct S){.x = 3.5}) compound_literal;
74*67e74705SXin Li 
75*67e74705SXin Li typedef typeof(i + sizeof(int[i + Enumerator])) add_result_with_typeinfo;
76*67e74705SXin Li 
77*67e74705SXin Li // ExtVectorElementExpr
78*67e74705SXin Li typedef __attribute__(( ext_vector_type(2) )) double double2;
79*67e74705SXin Li extern double2 vec2, vec2b;
80*67e74705SXin Li typedef typeof(vec2.x) ext_vector_element;
81*67e74705SXin Li 
82*67e74705SXin Li // InitListExpr
83*67e74705SXin Li double double_array[3] = { 1.0, 2.0 };
84*67e74705SXin Li 
85*67e74705SXin Li // DesignatedInitExpr
86*67e74705SXin Li struct {
87*67e74705SXin Li   int x;
88*67e74705SXin Li   float y;
89*67e74705SXin Li } designated_inits[3] = { [0].y = 17,
90*67e74705SXin Li                           [2].x = 12.3, // expected-warning {{implicit conversion from 'double' to 'int' changes value from 12.3 to 12}}
91*67e74705SXin Li                           3.5 };
92*67e74705SXin Li 
93*67e74705SXin Li // TypesCompatibleExpr
94*67e74705SXin Li typedef typeof(__builtin_types_compatible_p(float, double)) types_compatible;
95*67e74705SXin Li 
96*67e74705SXin Li // ChooseExpr
97*67e74705SXin Li typedef typeof(__builtin_choose_expr(17 > 19, d0, 1)) choose_expr;
98*67e74705SXin Li 
99*67e74705SXin Li // GNUNullExpr FIXME: needs C++
100*67e74705SXin Li // typedef typeof(__null) null_type;
101*67e74705SXin Li 
102*67e74705SXin Li // ShuffleVectorExpr
103*67e74705SXin Li typedef typeof(__builtin_shufflevector(vec2, vec2b, 2, 1)) shuffle_expr;
104*67e74705SXin Li 
105*67e74705SXin Li // ConvertVectorExpr
106*67e74705SXin Li typedef __attribute__(( ext_vector_type(2) )) float float2;
107*67e74705SXin Li typedef typeof(__builtin_convertvector(vec2, float2)) convert_expr;
108*67e74705SXin Li 
109*67e74705SXin Li // GenericSelectionExpr
110*67e74705SXin Li typedef typeof(_Generic(i, char*: 0, int: 0., default: hello))
111*67e74705SXin Li   generic_selection_expr;
112