[PATCH] D154359: [clang] Reset FP options before template instantiation

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 12 21:51:04 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGfde5924dcc69: [clang] Reset FP options before template instantiation (authored by sepavloff).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154359/new/

https://reviews.llvm.org/D154359

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGen/fp-template.cpp


Index: clang/test/CodeGen/fp-template.cpp
===================================================================
--- clang/test/CodeGen/fp-template.cpp
+++ clang/test/CodeGen/fp-template.cpp
@@ -45,10 +45,24 @@
 // CHECK:       call float @llvm.experimental.constrained.fsub.f32({{.*}}, metadata !"round.upward", metadata !"fpexcept.ignore")
 
 
-// This pragma sets non-default rounding mode before delayed parsing occurs. It
-// is used to check that the parsing uses FP options defined by command line
-// options or by pragma before the template definition but not by this pragma.
-#pragma STDC FENV_ROUND FE_TOWARDZERO
+#pragma STDC FENV_ROUND FE_TONEAREST
+
+namespace PR63542 {
+  template <class Compare> float stable_sort(float x, Compare) {
+    float result = x + x;
+    stable_sort(x, int());
+    return result;
+  }
+  float linkage_wrap() { return stable_sort(0.0, 1); }
+}
 
+// CHECK-LABEL: define {{.*}} float @_ZN7PR6354211stable_sortIiEEffT_(
+// CHECK:         fadd float
+
+// These pragmas set non-default FP environment before delayed parsing occurs.
+// It is used to check that the parsing uses FP options defined by command line
+// options or by pragma before the template definition but not by these pragmas.
+#pragma STDC FENV_ROUND FE_TOWARDZERO
+#pragma STDC FENV_ACCESS ON
 
 // CHECK: attributes #[[ATTR01]] = { {{.*}}strictfp
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5087,6 +5087,10 @@
     // PushDeclContext because we don't have a scope.
     Sema::ContextRAII savedContext(*this, Function);
 
+    FPFeaturesStateRAII SavedFPFeatures(*this);
+    CurFPFeatures = FPOptions(getLangOpts());
+    FpPragmaStack.CurrentValue = FPOptionsOverride();
+
     if (addInstantiatedParametersToScope(Function, PatternDecl, Scope,
                                          TemplateArgs))
       return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154359.539839.patch
Type: text/x-patch
Size: 2014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230713/3d5a04d9/attachment-0001.bin>


More information about the cfe-commits mailing list