1 // Test without serialization:
2 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-pc-linux -std=c++11 -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 -o %t %s
7 // RUN: %clang_cc1 -x c++ -triple x86_64-pc-linux -include-pch %t -ast-dump-all /dev/null \
8 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
9 // RUN: | FileCheck --strict-whitespace %s
10 
11 float func_01(float x);
12 
13 template <typename T>
14 T func_02(T x) {
15 #pragma STDC FP_CONTRACT ON
16   return func_01(x);
17 }
18 
19 float func_03(float x) {
20 #pragma STDC FP_CONTRACT OFF
21   return func_02(x);
22 }
23 
24 // CHECK:      FunctionTemplateDecl {{.*}} func_02
25 // CHECK:        FunctionDecl {{.*}} func_02 'float (float)'
26 // CHECK-NEXT:     TemplateArgument type 'float'
27 // CHECK-NEXT:       BuiltinType {{.*}} 'float'
28 // CHECK-NEXT:     ParmVarDecl {{.*}} x 'float'
29 // CHECK-NEXT:     CompoundStmt
30 // CHECK-NEXT:       ReturnStmt
31 // CHECK-NEXT:         CallExpr {{.*}} FPContractMode=1
32 
33 // CHECK:      FunctionDecl {{.*}} func_03 'float (float)'
34 // CHECK-NEXT:   ParmVarDecl {{.*}} x 'float'
35 // CHECK-NEXT:     CompoundStmt
36 // CHECK-NEXT:       ReturnStmt
37 // CHECK-NEXT:         CallExpr {{.*}} FPContractMode=0
38 
39 
40 
41 
42 #pragma STDC FENV_ROUND FE_DOWNWARD
43 
44 float func_10(float x, float y) {
45   return x + y;
46 }
47 
48 // CHECK-LABEL: FunctionDecl {{.*}} func_10 'float (float, float)'
49 // CHECK:         BinaryOperator {{.*}} 'float' '+' RoundingMode=3
50 
51 float func_11(float x, float y) {
52   if (x < 0) {
53     #pragma STDC FENV_ROUND FE_UPWARD
54     return x + y;
55   }
56   return x - y;
57 }
58 
59 // CHECK-LABEL: FunctionDecl {{.*}} func_11 'float (float, float)'
60 // CHECK:         BinaryOperator {{.*}} 'float' '+' RoundingMode=2
61 // CHECK:         BinaryOperator {{.*}} 'float' '-' RoundingMode=3
62 
63 
64 #pragma STDC FENV_ROUND FE_DYNAMIC
65 
66 float func_12(float x, float y) {
67   return x + y;
68 }
69 
70 // CHECK-LABEL: FunctionDecl {{.*}} func_12 'float (float, float)'
71 // CHECK:         BinaryOperator {{.*}} 'float' '+' RoundingMode=1
72 
73 #pragma STDC FENV_ROUND FE_TONEAREST
74 
75 float func_13(float x, float y) {
76   return x + y;
77 }
78 
79 // CHECK-LABEL: FunctionDecl {{.*}} func_13 'float (float, float)'
80 // CHECK:         BinaryOperator {{.*}} 'float' '+' RoundingMode=1
81 
82 
83 template <typename T>
84 T func_14(T x, T y) {
85 #pragma STDC FENV_ROUND FE_TOWARDZERO
86   return x + y;
87 }
88 
89 float func_15(float x, float y) {
90 #pragma STDC FPENV_ROUND FE_DOWNWARD
91   return func_14(x, y);
92 }
93 
94 // CHECK-LABEL: FunctionTemplateDecl {{.*}} func_14
95 // CHECK:         FunctionDecl {{.*}} func_14 'T (T, T)'
96 // CHECK:           CompoundStmt
97 // CHECK-NEXT:        ReturnStmt
98 // CHECK-NEXT:          BinaryOperator {{.*}} '+' RoundingMode=0
99 // CHECK:         FunctionDecl {{.*}} func_14 'float (float, float)'
100 // CHECK:           CompoundStmt
101 // CHECK-NEXT:        ReturnStmt
102 // CHECK-NEXT:          BinaryOperator {{.*}} 'float' '+' RoundingMode=0
103