diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4923,6 +4923,11 @@ PatternDecl->hasSkippedBody()) && "unexpected kind of function template definition"); + // If a function template is marked as strictfp, its instantiations should + // also have this attribute. + if (PatternDecl->hasAttr()) + Function->addAttr(StrictFPAttr::CreateImplicit(Context)); + // C++1y [temp.explicit]p10: // Except for inline functions, declarations with types deduced from their // initializer or return value, and class template specializations, other diff --git a/clang/test/CodeGen/fp-template.cpp b/clang/test/CodeGen/fp-template.cpp new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/fp-template.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -fdelayed-template-parsing -o - %s | FileCheck %s + +template +T templ_01(T x, T y) { +#pragma STDC FENV_ACCESS ON + return x + y; +} + +float func_01(float x, float y) { + return templ_01(x, y); +} + +// CHECK-LABEL: define {{.*}} @_Z8templ_01IfET_S0_S0_ +// CHECK-SAME: (float noundef %{{.*}}, float noundef %{{.*}}) #[[ATTR01:[0-9]+]]{{.*}} { +// CHECK: call float @llvm.experimental.constrained.fadd.f32 + +// CHECK: attributes #[[ATTR01]] = { {{.*}}strictfp