mibintc created this revision.
mibintc added reviewers: kpn, sepavloff, aaron.ballman, pengfei.
Herald added a project: clang.
mibintc requested review of this revision.
Herald added a subscriber: aheejin.

If the target doesn't support setting StrictFP, then ignore pragmas that modify 
the settings for rounding mode and exception behavior and FENV_ACCESS.
This was requested by @kpn see https://bugs.llvm.org/show_bug.cgi?id=47536
Also @pengfei suggested it as a solution for 
https://bugs.llvm.org/show_bug.cgi?id=47990


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90316

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParsePragma.cpp
  clang/test/Parser/pragma-fp-warn.c


Index: clang/test/Parser/pragma-fp-warn.c
===================================================================
--- /dev/null
+++ clang/test/Parser/pragma-fp-warn.c
@@ -0,0 +1,19 @@
+
+// RUN: %clang_cc1 -triple wasm32 -fsyntax-only -Wno-unknown-pragmas 
-Wignored-pragmas -verify %s
+// RUN: %clang_cc1 -triple thumbv7 -fsyntax-only -Wno-unknown-pragmas 
-Wignored-pragmas -verify %s
+// RUN: %clang_cc1 -triple aarch64 -fsyntax-only -Wno-unknown-pragmas 
-Wignored-pragmas -verify %s
+// RUN: %clang_cc1 -DEXPOK -triple x86_64 -fsyntax-only -Wno-unknown-pragmas 
-Wignored-pragmas -verify %s
+// RUN: %clang_cc1 -DEXPOK -triple systemz -fsyntax-only -Wno-unknown-pragmas 
-Wignored-pragmas -verify %s
+// RUN: %clang_cc1 -DEXPOK -triple powerpc -fsyntax-only -Wno-unknown-pragmas 
-Wignored-pragmas -verify %s
+#ifdef EXPOK
+// expected-no-diagnostics
+#else
+// expected-warning@+8 {{'#pragma FENV_ROUND' is not supported on this target 
- ignored}}
+// expected-warning@+5 {{'#pragma FENV_ACCESS' is not supported on this target 
- ignored}}
+// expected-warning@+2 {{'#pragma float_control' is not supported on this 
target - ignored}}
+#endif
+#pragma float_control(precise, on)
+
+#pragma STDC FENV_ACCESS OFF
+
+#pragma STDC FENV_ROUND FE_DOWNWARD
Index: clang/lib/Parse/ParsePragma.cpp
===================================================================
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -103,6 +103,11 @@
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
                     Token &Tok) override {
+    if (!PP.getTargetInfo().hasStrictFP()) {
+      PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+          << "FENV_ACCESS";
+      return;
+    }
     tok::OnOffSwitch OOS;
     if (PP.LexOnOffSwitch(OOS))
      return;
@@ -2553,6 +2558,11 @@
                                              Token &Tok) {
   Sema::PragmaMsStackAction Action = Sema::PSK_Set;
   SourceLocation FloatControlLoc = Tok.getLocation();
+  if (!PP.getTargetInfo().hasStrictFP()) {
+    PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+        << "float_control";
+    return;
+  }
   PP.Lex(Tok);
   if (Tok.isNot(tok::l_paren)) {
     PP.Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
@@ -2952,6 +2962,11 @@
                                                 Token &Tok) {
   Token PragmaName = Tok;
   SmallVector<Token, 1> TokenList;
+  if (!PP.getTargetInfo().hasStrictFP()) {
+    PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+        << PragmaName.getIdentifierInfo()->getName();
+    return;
+  }
 
   PP.Lex(Tok);
   if (Tok.isNot(tok::identifier)) {
Index: clang/include/clang/Basic/DiagnosticParseKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticParseKinds.td
+++ clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1147,6 +1147,9 @@
 def warn_stdc_unknown_rounding_mode : Warning<
   "invalid or unsupported rounding mode in '#pragma STDC FENV_ROUND' - 
ignored">,
   InGroup<IgnoredPragmas>;
+def warn_pragma_fp_ignored : Warning<
+  "'#pragma %0' is not supported on this target - ignored">,
+  InGroup<IgnoredPragmas>;
 // - #pragma comment
 def err_pragma_comment_malformed : Error<
   "pragma comment requires parenthesized identifier and optional string">;


Index: clang/test/Parser/pragma-fp-warn.c
===================================================================
--- /dev/null
+++ clang/test/Parser/pragma-fp-warn.c
@@ -0,0 +1,19 @@
+
+// RUN: %clang_cc1 -triple wasm32 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
+// RUN: %clang_cc1 -triple thumbv7 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
+// RUN: %clang_cc1 -triple aarch64 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
+// RUN: %clang_cc1 -DEXPOK -triple x86_64 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
+// RUN: %clang_cc1 -DEXPOK -triple systemz -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
+// RUN: %clang_cc1 -DEXPOK -triple powerpc -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
+#ifdef EXPOK
+// expected-no-diagnostics
+#else
+// expected-warning@+8 {{'#pragma FENV_ROUND' is not supported on this target - ignored}}
+// expected-warning@+5 {{'#pragma FENV_ACCESS' is not supported on this target - ignored}}
+// expected-warning@+2 {{'#pragma float_control' is not supported on this target - ignored}}
+#endif
+#pragma float_control(precise, on)
+
+#pragma STDC FENV_ACCESS OFF
+
+#pragma STDC FENV_ROUND FE_DOWNWARD
Index: clang/lib/Parse/ParsePragma.cpp
===================================================================
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -103,6 +103,11 @@
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
                     Token &Tok) override {
+    if (!PP.getTargetInfo().hasStrictFP()) {
+      PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+          << "FENV_ACCESS";
+      return;
+    }
     tok::OnOffSwitch OOS;
     if (PP.LexOnOffSwitch(OOS))
      return;
@@ -2553,6 +2558,11 @@
                                              Token &Tok) {
   Sema::PragmaMsStackAction Action = Sema::PSK_Set;
   SourceLocation FloatControlLoc = Tok.getLocation();
+  if (!PP.getTargetInfo().hasStrictFP()) {
+    PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+        << "float_control";
+    return;
+  }
   PP.Lex(Tok);
   if (Tok.isNot(tok::l_paren)) {
     PP.Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
@@ -2952,6 +2962,11 @@
                                                 Token &Tok) {
   Token PragmaName = Tok;
   SmallVector<Token, 1> TokenList;
+  if (!PP.getTargetInfo().hasStrictFP()) {
+    PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+        << PragmaName.getIdentifierInfo()->getName();
+    return;
+  }
 
   PP.Lex(Tok);
   if (Tok.isNot(tok::identifier)) {
Index: clang/include/clang/Basic/DiagnosticParseKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticParseKinds.td
+++ clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1147,6 +1147,9 @@
 def warn_stdc_unknown_rounding_mode : Warning<
   "invalid or unsupported rounding mode in '#pragma STDC FENV_ROUND' - ignored">,
   InGroup<IgnoredPragmas>;
+def warn_pragma_fp_ignored : Warning<
+  "'#pragma %0' is not supported on this target - ignored">,
+  InGroup<IgnoredPragmas>;
 // - #pragma comment
 def err_pragma_comment_malformed : Error<
   "pragma comment requires parenthesized identifier and optional string">;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to