[PATCH] D98211: Solve PR49479, File scope fp pragma should propagate to functions nested in struct, and initialization expressions

Melanie Blower via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 8 12:13:41 PST 2021


mibintc created this revision.
mibintc added reviewers: kpn, erichkeane, rjmccall.
mibintc requested review of this revision.
Herald added a project: clang.

Currently, the CurFPFeatures state is set to command line settings before semantic analysis of the nested member functions and initialization expressions, that's not correct.  This patch fixes that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98211

Files:
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/CodeGen/fp-floatcontrol-stack.cpp


Index: clang/test/CodeGen/fp-floatcontrol-stack.cpp
===================================================================
--- clang/test/CodeGen/fp-floatcontrol-stack.cpp
+++ clang/test/CodeGen/fp-floatcontrol-stack.cpp
@@ -212,8 +212,7 @@
 #endif
                                             float y();
 class ON {
-  // Settings for top level class initializer revert to command line
-  // source pragma's do not pertain.
+  // Settings for top level class initializer use program source setting.
   float z = 2 + y() * 7;
 //CHECK-LABEL: define {{.*}} void @_ZN2ONC2Ev{{.*}}
 #if DEFAULT
@@ -224,11 +223,10 @@
 //CHECK-DEBSTRICT: call float {{.*}}llvm.fmuladd
 #endif
 #if NOHONOR
-//CHECK-NOHONOR: call nnan ninf float @llvm.fmuladd{{.*}}
+//CHECK-NOHONOR: call float {{.*}}llvm.fmuladd
 #endif
 #if FAST
-//CHECK-FAST: fmul fast float
-//CHECK-FAST: fadd fast float
+//CHECK-FAST: float {{.*}}llvm.fmuladd{{.*}}
 #endif
 };
 ON on;
@@ -236,18 +234,28 @@
 class OFF {
   float w = 2 + y() * 7;
 //CHECK-LABEL: define {{.*}} void @_ZN3OFFC2Ev{{.*}}
-#if DEFAULT
-//CHECK-DDEFAULT: call float {{.*}}llvm.fmuladd
-#endif
-#if EBSTRICT
-//CHECK-DEBSTRICT: call float {{.*}}llvm.fmuladd
-#endif
-#if NOHONOR
-//CHECK-NOHONOR: call nnan ninf float @llvm.fmuladd{{.*}}
-#endif
-#if FAST
-//CHECK-FAST: fmul fast float
-//CHECK-FAST: fadd fast float
-#endif
+//CHECK: call float {{.*}}llvm.fmuladd
 };
 OFF off;
+
+#pragma clang fp reassociate(on)
+struct MyComplex {
+  float xx;
+  float yy;
+  MyComplex(float x, float y) {
+    xx = x;
+    yy = y;
+  }
+  MyComplex() {}
+  const MyComplex operator+(const MyComplex other) const {
+//CHECK-LABEL: define {{.*}} @_ZNK9MyComplexplES_
+//CHECK: fadd reassoc float
+//CHECK: fadd reassoc float
+    return MyComplex(xx + other.xx, yy + other.yy);
+  }
+};
+MyComplex useAdd() {
+  MyComplex a (1, 3);
+  MyComplex b (2, 4);
+   return a + b;
+}
Index: clang/lib/Parse/ParseDeclCXX.cpp
===================================================================
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -3417,15 +3417,6 @@
     // declarations and the lexed inline method definitions, along with any
     // delayed attributes.
 
-    // Save the state of Sema.FPFeatures, and change the setting
-    // to the levels specified on the command line.  Previous level
-    // will be restored when the RAII object is destroyed.
-    Sema::FPFeaturesStateRAII SaveFPFeaturesState(Actions);
-    FPOptionsOverride NewOverrides;
-    Actions.CurFPFeatures = NewOverrides.applyOverrides(getLangOpts());
-    Actions.FpPragmaStack.Act(Tok.getLocation(), Sema::PSK_Reset, StringRef(),
-                              {} /*unused*/);
-
     SourceLocation SavedPrevTokLocation = PrevTokLocation;
     ParseLexedPragmas(getCurrentClass());
     ParseLexedAttributes(getCurrentClass());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98211.329094.patch
Type: text/x-patch
Size: 2846 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210308/eea81825/attachment.bin>


More information about the cfe-commits mailing list