xref: /llvm-project/clang/test/CodeGen/fp-template.cpp (revision fde5924dcc69fe814085482df259b8cfee236f2c)
15cc91f97SSerge Pavlov // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
25cc91f97SSerge Pavlov // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -fdelayed-template-parsing -o - %s | FileCheck %s
35cc91f97SSerge Pavlov 
45cc91f97SSerge Pavlov template <typename T>
templ_01(T x,T y)55cc91f97SSerge Pavlov T templ_01(T x, T y) {
65cc91f97SSerge Pavlov #pragma STDC FENV_ACCESS ON
75cc91f97SSerge Pavlov   return x + y;
85cc91f97SSerge Pavlov }
95cc91f97SSerge Pavlov 
func_01(float x,float y)105cc91f97SSerge Pavlov float func_01(float x, float y) {
115cc91f97SSerge Pavlov   return templ_01(x, y);
125cc91f97SSerge Pavlov }
135cc91f97SSerge Pavlov 
145cc91f97SSerge Pavlov // CHECK-LABEL: define {{.*}} @_Z8templ_01IfET_S0_S0_
155cc91f97SSerge Pavlov // CHECK-SAME:  (float noundef %{{.*}}, float noundef %{{.*}}) #[[ATTR01:[0-9]+]]{{.*}} {
165cc91f97SSerge Pavlov // CHECK:       call float @llvm.experimental.constrained.fadd.f32
175cc91f97SSerge Pavlov 
182e903709SSerge Pavlov 
192e903709SSerge Pavlov template <typename Ty>
templ_02(Ty x,Ty y)202e903709SSerge Pavlov Ty templ_02(Ty x, Ty y) {
212e903709SSerge Pavlov   return x + y;
222e903709SSerge Pavlov }
232e903709SSerge Pavlov 
242e903709SSerge Pavlov #pragma STDC FENV_ROUND FE_UPWARD
252e903709SSerge Pavlov 
262e903709SSerge Pavlov template <typename Ty>
templ_03(Ty x,Ty y)272e903709SSerge Pavlov Ty templ_03(Ty x, Ty y) {
282e903709SSerge Pavlov   return x - y;
292e903709SSerge Pavlov }
302e903709SSerge Pavlov 
312e903709SSerge Pavlov #pragma STDC FENV_ROUND FE_TONEAREST
322e903709SSerge Pavlov 
func_02(float x,float y)332e903709SSerge Pavlov float func_02(float x, float y) {
342e903709SSerge Pavlov   return templ_02(x, y);
352e903709SSerge Pavlov }
362e903709SSerge Pavlov 
372e903709SSerge Pavlov // CHECK-LABEL: define {{.*}} float @_Z8templ_02IfET_S0_S0_
382e903709SSerge Pavlov // CHECK:       %add = fadd float %0, %1
392e903709SSerge Pavlov 
func_03(float x,float y)402e903709SSerge Pavlov float func_03(float x, float y) {
412e903709SSerge Pavlov   return templ_03(x, y);
422e903709SSerge Pavlov }
432e903709SSerge Pavlov 
442e903709SSerge Pavlov // CHECK-LABEL: define {{.*}} float @_Z8templ_03IfET_S0_S0_
452e903709SSerge Pavlov // CHECK:       call float @llvm.experimental.constrained.fsub.f32({{.*}}, metadata !"round.upward", metadata !"fpexcept.ignore")
462e903709SSerge Pavlov 
472e903709SSerge Pavlov 
48*fde5924dSSerge Pavlov #pragma STDC FENV_ROUND FE_TONEAREST
492e903709SSerge Pavlov 
50*fde5924dSSerge Pavlov namespace PR63542 {
stable_sort(float x,Compare)51*fde5924dSSerge Pavlov   template <class Compare> float stable_sort(float x, Compare) {
52*fde5924dSSerge Pavlov     float result = x + x;
53*fde5924dSSerge Pavlov     stable_sort(x, int());
54*fde5924dSSerge Pavlov     return result;
55*fde5924dSSerge Pavlov   }
linkage_wrap()56*fde5924dSSerge Pavlov   float linkage_wrap() { return stable_sort(0.0, 1); }
57*fde5924dSSerge Pavlov }
58*fde5924dSSerge Pavlov 
59*fde5924dSSerge Pavlov // CHECK-LABEL: define {{.*}} float @_ZN7PR6354211stable_sortIiEEffT_(
60*fde5924dSSerge Pavlov // CHECK:         fadd float
61*fde5924dSSerge Pavlov 
62*fde5924dSSerge Pavlov // These pragmas set non-default FP environment before delayed parsing occurs.
63*fde5924dSSerge Pavlov // It is used to check that the parsing uses FP options defined by command line
64*fde5924dSSerge Pavlov // options or by pragma before the template definition but not by these pragmas.
65*fde5924dSSerge Pavlov #pragma STDC FENV_ROUND FE_TOWARDZERO
66*fde5924dSSerge Pavlov #pragma STDC FENV_ACCESS ON
672e903709SSerge Pavlov 
685cc91f97SSerge Pavlov // CHECK: attributes #[[ATTR01]] = { {{.*}}strictfp
69