1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -fdelayed-template-parsing -o - %s | FileCheck %s
3
4 template <typename T>
templ_01(T x,T y)5 T templ_01(T x, T y) {
6 #pragma STDC FENV_ACCESS ON
7 return x + y;
8 }
9
func_01(float x,float y)10 float func_01(float x, float y) {
11 return templ_01(x, y);
12 }
13
14 // CHECK-LABEL: define {{.*}} @_Z8templ_01IfET_S0_S0_
15 // CHECK-SAME: (float noundef %{{.*}}, float noundef %{{.*}}) #[[ATTR01:[0-9]+]]{{.*}} {
16 // CHECK: call float @llvm.experimental.constrained.fadd.f32
17
18
19 template <typename Ty>
templ_02(Ty x,Ty y)20 Ty templ_02(Ty x, Ty y) {
21 return x + y;
22 }
23
24 #pragma STDC FENV_ROUND FE_UPWARD
25
26 template <typename Ty>
templ_03(Ty x,Ty y)27 Ty templ_03(Ty x, Ty y) {
28 return x - y;
29 }
30
31 #pragma STDC FENV_ROUND FE_TONEAREST
32
func_02(float x,float y)33 float func_02(float x, float y) {
34 return templ_02(x, y);
35 }
36
37 // CHECK-LABEL: define {{.*}} float @_Z8templ_02IfET_S0_S0_
38 // CHECK: %add = fadd float %0, %1
39
func_03(float x,float y)40 float func_03(float x, float y) {
41 return templ_03(x, y);
42 }
43
44 // CHECK-LABEL: define {{.*}} float @_Z8templ_03IfET_S0_S0_
45 // CHECK: call float @llvm.experimental.constrained.fsub.f32({{.*}}, metadata !"round.upward", metadata !"fpexcept.ignore")
46
47
48 #pragma STDC FENV_ROUND FE_TONEAREST
49
50 namespace PR63542 {
stable_sort(float x,Compare)51 template <class Compare> float stable_sort(float x, Compare) {
52 float result = x + x;
53 stable_sort(x, int());
54 return result;
55 }
linkage_wrap()56 float linkage_wrap() { return stable_sort(0.0, 1); }
57 }
58
59 // CHECK-LABEL: define {{.*}} float @_ZN7PR6354211stable_sortIiEEffT_(
60 // CHECK: fadd float
61
62 // These pragmas set non-default FP environment before delayed parsing occurs.
63 // It is used to check that the parsing uses FP options defined by command line
64 // options or by pragma before the template definition but not by these pragmas.
65 #pragma STDC FENV_ROUND FE_TOWARDZERO
66 #pragma STDC FENV_ACCESS ON
67
68 // CHECK: attributes #[[ATTR01]] = { {{.*}}strictfp
69