sepavloff created this revision. sepavloff added reviewers: rsmith, rjmccall, aaron.ballman, efriedma. Herald added a project: All. sepavloff requested review of this revision. Herald added a project: clang.
If a template function contained a pragma that made it strictfp, code generation for such function crashed, because the instantiation did not have strictfp attribute. As a solution this attribute is copied from the template to instantiation. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D143919 Files: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/test/CodeGen/fp-template.cpp Index: clang/test/CodeGen/fp-template.cpp =================================================================== --- /dev/null +++ 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 <typename T> +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 Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp =================================================================== --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ 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<StrictFPAttr>()) + 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
Index: clang/test/CodeGen/fp-template.cpp =================================================================== --- /dev/null +++ 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 <typename T> +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 Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp =================================================================== --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ 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<StrictFPAttr>()) + 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits