[PATCH] D143919: [Clang] Copy strictfp attribute from pattern to instantiation
Serge Pavlov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 13 08:01:27 PST 2023
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143919.496993.patch
Type: text/x-patch
Size: 1567 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230213/b0801272/attachment-0001.bin>
More information about the cfe-commits
mailing list