Debian Codegraph @

clang/test/AST/ast-dump-fpfeatures.cpp

raw
1 // Test without serialization:
2 // RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++11 -fcxx-exceptions -ast-dump %s \
3 // RUN: | FileCheck --strict-whitespace %s
4
5 // Test with serialization:
6 // RUN: %clang_cc1 -triple x86_64-pc-linux -emit-pch -fcxx-exceptions -o %t %s
7 // RUN: %clang_cc1 -x c++ -triple x86_64-pc-linux -include-pch %t -fcxx-exceptions -ast-dump-all /dev/null \
8 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
9 // RUN: | FileCheck --strict-whitespace %s
10
11 // CHECK-LABEL: FunctionDecl {{.*}} no_fpfeatures_func_01 'vector2float (vector2double)'
12 // CHECK: CompoundStmt {{.*\>$}}
13 // CHECK: ReturnStmt
14 // CHECK: ConvertVectorExpr {{.*}} 'vector2float':'__attribute__((__vector_size__(2 * sizeof(float)))) float'{{$}}
15
16 typedef double vector2double __attribute__((__vector_size__(16)));
17 typedef float vector2float __attribute__((__vector_size__(8)));
18 vector2float no_fpfeatures_func_01(vector2double x) {
19 return __builtin_convertvector(x, vector2float);
20 }
21
22 float func_01(float x);
23
24 template <typename T>
25 T func_02(T x) {
26 #pragma STDC FP_CONTRACT ON
27 return func_01(x);
28 }
29
30 float func_03(float x) {
31 #pragma STDC FP_CONTRACT OFF
32 return func_02(x);
33 }
34
35 // CHECK: FunctionTemplateDecl {{.*}} func_02
36 // CHECK: FunctionDecl {{.*}} func_02 'float (float)'
37 // CHECK-NEXT: TemplateArgument type 'float'
38 // CHECK-NEXT: BuiltinType {{.*}} 'float'
39 // CHECK-NEXT: ParmVarDecl {{.*}} x 'float'
40 // CHECK-NEXT: CompoundStmt
41 // CHECK-NEXT: ReturnStmt
42 // CHECK-NEXT: CallExpr {{.*}} FPContractMode=1
43
44 // CHECK: FunctionDecl {{.*}} func_03 'float (float)'
45 // CHECK-NEXT: ParmVarDecl {{.*}} x 'float'
46 // CHECK-NEXT: CompoundStmt
47 // CHECK-NEXT: ReturnStmt
48 // CHECK-NEXT: CallExpr {{.*}} FPContractMode=0
49
50 int func_04(float x) {
51 #pragma STDC FP_CONTRACT ON
52 return x;
53 }
54
55 // CHECK: FunctionDecl {{.*}} func_04 'int (float)'
56 // CHECK-NEXT: ParmVarDecl {{.*}} x 'float'
57 // CHECK-NEXT: CompoundStmt
58 // CHECK-NEXT: ReturnStmt
59 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'int' <FloatingToIntegral> FPContractMode=1
60
61 float func_05(double x) {
62 #pragma STDC FP_CONTRACT ON
63 return (float)x;
64 }
65
66 // CHECK: FunctionDecl {{.*}} func_05 'float (double)'
67 // CHECK-NEXT: ParmVarDecl {{.*}} x 'double'
68 // CHECK-NEXT: CompoundStmt
69 // CHECK-NEXT: ReturnStmt
70 // CHECK-NEXT: CStyleCastExpr {{.*}} FPContractMode=1
71
72 float func_06(double x) {
73 #pragma STDC FP_CONTRACT ON
74 return float(x);
75 }
76
77 // CHECK: FunctionDecl {{.*}} func_06 'float (double)'
78 // CHECK-NEXT: ParmVarDecl {{.*}} x 'double'
79 // CHECK-NEXT: CompoundStmt
80 // CHECK-NEXT: ReturnStmt
81 // CHECK-NEXT: CXXFunctionalCastExpr {{.*}} FPContractMode=1
82
83 float func_07(double x) {
84 #pragma STDC FP_CONTRACT ON
85 return static_cast<float>(x);
86 }
87
88 // CHECK: FunctionDecl {{.*}} func_07 'float (double)'
89 // CHECK-NEXT: ParmVarDecl {{.*}} x 'double'
90 // CHECK-NEXT: CompoundStmt
91 // CHECK-NEXT: ReturnStmt
92 // CHECK-NEXT: CXXStaticCastExpr {{.*}} FPContractMode=1
93
94 #pragma STDC FENV_ROUND FE_DOWNWARD
95
96 float func_10(float x, float y) {
97 return x + y;
98 }
99
100 // CHECK-LABEL: FunctionDecl {{.*}} func_10 'float (float, float)'
101 // CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=downward
102
103 float func_11(float x, float y) {
104 if (x < 0) {
105 #pragma STDC FENV_ROUND FE_UPWARD
106 return x + y;
107 }
108 return x - y;
109 }
110
111 // CHECK-LABEL: FunctionDecl {{.*}} func_11 'float (float, float)'
112 // CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=upward
113 // CHECK: BinaryOperator {{.*}} 'float' '-' ConstRoundingMode=downward
114
115
116 #pragma STDC FENV_ROUND FE_DYNAMIC
117
118 float func_12(float x, float y) {
119 return x + y;
120 }
121
122 // CHECK-LABEL: FunctionDecl {{.*}} func_12 'float (float, float)'
123 // CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=dynamic
124
125 #pragma STDC FENV_ROUND FE_TONEAREST
126
127 float func_13(float x, float y) {
128 return x + y;
129 }
130
131 // CHECK-LABEL: FunctionDecl {{.*}} func_13 'float (float, float)'
132 // CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=tonearest
133
134
135 template <typename T>
136 T func_14(T x, T y) {
137 #pragma STDC FENV_ROUND FE_TOWARDZERO
138 return x + y;
139 }
140
141 float func_15(float x, float y) {
142 #pragma STDC FENV_ROUND FE_DOWNWARD
143 return func_14(x, y);
144 }
145
146 // CHECK-LABEL: FunctionTemplateDecl {{.*}} func_14
147 // CHECK: FunctionDecl {{.*}} func_14 'T (T, T)'
148 // CHECK: CompoundStmt
149 // CHECK-NEXT: ReturnStmt
150 // CHECK-NEXT: BinaryOperator {{.*}} '+' ConstRoundingMode=towardzero
151 // CHECK: FunctionDecl {{.*}} func_14 'float (float, float)'
152 // CHECK: CompoundStmt
153 // CHECK-NEXT: ReturnStmt
154 // CHECK-NEXT: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=towardzero
155
156 float func_16(float x, float y) {
157 #pragma STDC FENV_ROUND FE_TOWARDZERO
158 if (x < 0) {
159 #pragma STDC FENV_ROUND FE_UPWARD
160 return x - y;
161 }
162 return x + y;
163 }
164
165 // CHECK-LABEL: FunctionDecl {{.*}} func_16 'float (float, float)'
166 // CHECK: CompoundStmt {{.*}} ConstRoundingMode=towardzero
167 // CHECK: IfStmt
168 // CHECK: CompoundStmt {{.*}} ConstRoundingMode=upward
169 // CHECK: ReturnStmt
170 // CHECK: BinaryOperator {{.*}} ConstRoundingMode=upward
171 // CHECK: ReturnStmt
172 // CHECK: BinaryOperator {{.*}} ConstRoundingMode=towardzero
173
174 float func_17(float x, float y) {
175 #pragma STDC FENV_ROUND FE_TOWARDZERO
176 if (x < 0) {
177 #pragma STDC FENV_ROUND FE_TOWARDZERO
178 return x - y;
179 }
180 return x + y;
181 }
182
183 // CHECK-LABEL: FunctionDecl {{.*}} func_17 'float (float, float)'
184 // CHECK: CompoundStmt {{.*}} ConstRoundingMode=towardzero
185 // CHECK: IfStmt
186 // CHECK: CompoundStmt {{.*}}
187 // CHECK: ReturnStmt
188 // CHECK: BinaryOperator {{.*}} ConstRoundingMode=towardzero
189 // CHECK: ReturnStmt
190 // CHECK: BinaryOperator {{.*}} ConstRoundingMode=towardzero
191
192 #pragma STDC FENV_ROUND FE_DOWNWARD
193 float func_18(float x, float y) {
194 return x + y;
195 }
196
197 // CHECK-LABEL: FunctionDecl {{.*}} func_18 'float (float, float)'
198 // CHECK: CompoundStmt {{.*}} ConstRoundingMode=downward
199 // CHECK: ReturnStmt
200 // CHECK: BinaryOperator {{.*}} ConstRoundingMode=downward
201
202 #pragma float_control(precise, off)
203
204 __attribute__((optnone))
205 float func_19(float x, float y) {
206 return x + y;
207 }
208
209 // CHECK-LABEL: FunctionDecl {{.*}} func_19 'float (float, float)'
210 // CHECK: CompoundStmt {{.*}} MathErrno=1
211 // CHECK: ReturnStmt
212 // CHECK: BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
213
214 __attribute__((optnone))
215 float func_20(float x, float y) try {
216 return x + y;
217 } catch (...) {
218 return 1.0;
219 }
220
221 // CHECK-LABEL: FunctionDecl {{.*}} func_20 'float (float, float)'
222 // CHECK: CompoundStmt {{.*}} ConstRoundingMode=downward MathErrno=1
223 // CHECK: ReturnStmt
224 // CHECK: BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
225
226 struct C21 {
227 C21(float x, float y);
228 __attribute__((optnone)) float a_method(float x, float y) {
229 return x * y;
230 }
231 float member;
232 };
233
234 // CHECK-LABEL: CXXMethodDecl {{.*}} a_method 'float (float, float)'
235 // CHECK: CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
236 // CHECK: ReturnStmt
237 // CHECK: BinaryOperator {{.*}} 'float' '*' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
238
239 __attribute__((optnone)) C21::C21(float x, float y) : member(x + y) {}
240
241 // CHECK-LABEL: CXXConstructorDecl {{.*}} C21 'void (float, float)'
242 // CHECK: CXXCtorInitializer {{.*}} 'member' 'float'
243 // CHECK: BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
244
245 template <typename T>
246 __attribute__((optnone)) T func_22(T x, T y) {
247 return x + y;
248 }
249
250 // CHECK-LABEL: FunctionTemplateDecl {{.*}} func_22
251 // CHECK: FunctionDecl {{.*}} func_22 'T (T, T)'
252 // CHECK: CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
253 // CHECK: ReturnStmt
254 // CHECK: BinaryOperator {{.*}} '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
255 // CHECK: FunctionDecl {{.*}} func_22 'float (float, float)'
256 // CHECK: CompoundStmt {{.*}} FPContractMode=1 ConstRoundingMode=downward MathErrno=1
257 // CHECK: ReturnStmt
258 // CHECK: BinaryOperator {{.*}} 'float' '+' FPContractMode=1 ConstRoundingMode=downward MathErrno=1
259
260 float func_23(float x, float y) {
261 return func_22(x, y);
262 }
263
264 // CHECK-LABEL: FunctionDecl {{.*}} func_24 'vector2float (vector2double)'
265 // CHECK: CompoundStmt {{.*}} FPContractMode=2 ConstRoundingMode=towardzero
266 // CHECK: ReturnStmt
267 // CHECK: ConvertVectorExpr {{.*}} FPContractMode=2 ConstRoundingMode=towardzero
268
269 #pragma STDC FENV_ROUND FE_TOWARDZERO
270 vector2float func_24(vector2double x) {
271 return __builtin_convertvector(x, vector2float);
272 }