[PATCH] D90316: [FPEnv] Diagnose pragmas FENV_ROUND,_ACCESS and float_control if target does not support StrictFP

2020-10-30 Thread Melanie Blower via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
mibintc marked an inline comment as done.
Closed by commit rG13bfd89c4962: [clang][FPEnv] Diagnose Strict FP pragmas if 
target does not support StrictFP (authored by mibintc).

Repository:
  rG LLVM Github Monorepo

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

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@+4 {{'#pragma float_control' is not supported on this 
target - ignored}}
+// expected-warning@+5 {{'#pragma FENV_ACCESS' is not supported on this target 
- ignored}}
+// expected-warning@+6 {{'#pragma FENV_ROUND' 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,12 @@
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
 Token &Tok) override {
+Token PragmaName = Tok;
+if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
+  PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+  << PragmaName.getIdentifierInfo()->getName();
+  return;
+}
 tok::OnOffSwitch OOS;
 if (PP.LexOnOffSwitch(OOS))
  return;
@@ -2553,6 +2559,12 @@
  Token &Tok) {
   Sema::PragmaMsStackAction Action = Sema::PSK_Set;
   SourceLocation FloatControlLoc = Tok.getLocation();
+  Token PragmaName = Tok;
+  if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
+PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+<< PragmaName.getIdentifierInfo()->getName();
+return;
+  }
   PP.Lex(Tok);
   if (Tok.isNot(tok::l_paren)) {
 PP.Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
@@ -2952,6 +2964,11 @@
 Token &Tok) {
   Token PragmaName = Tok;
   SmallVector TokenList;
+  if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
+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;
+def warn_pragma_fp_ignored : Warning<
+  "'#pragma %0' is not supported on this target - ignored">,
+  InGroup;
 // - #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@+4 {{'#pragma float_control' is not supported 

[PATCH] D90316: [FPEnv] Diagnose pragmas FENV_ROUND,_ACCESS and float_control if target does not support StrictFP

2020-10-30 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff accepted this revision.
sepavloff added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: clang/test/Parser/pragma-fp-warn.c:1
+
+// RUN: %clang_cc1 -triple wasm32 -fsyntax-only -Wno-unknown-pragmas 
-Wignored-pragmas -verify %s

I would propose to add a line with `-triple msp430`. This is a simple core, it 
is unlikely that it gets hardware FP support.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90316

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90316: [FPEnv] Diagnose pragmas FENV_ROUND,_ACCESS and float_control if target does not support StrictFP

2020-10-29 Thread Melanie Blower via Phabricator via cfe-commits
mibintc marked 2 inline comments as done.
mibintc added inline comments.



Comment at: clang/lib/Parse/ParsePragma.cpp:2967
+PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+<< PragmaName.getIdentifierInfo()->getName();
+return;

aaron.ballman wrote:
> Can you pass in `PragmaName` directly, or does that do unfortunate things 
> with single quotes?
After I changed it to PragmaName, the clang-format didn't find anything to fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90316

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90316: [FPEnv] Diagnose pragmas FENV_ROUND,_ACCESS and float_control if target does not support StrictFP

2020-10-29 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 301708.
mibintc added a comment.

respond to @aaron.ballman 's review


Repository:
  rG LLVM Github Monorepo

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

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@+4 {{'#pragma float_control' is not supported on this 
target - ignored}}
+// expected-warning@+5 {{'#pragma FENV_ACCESS' is not supported on this target 
- ignored}}
+// expected-warning@+6 {{'#pragma FENV_ROUND' 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,12 @@
 
   void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
 Token &Tok) override {
+Token PragmaName = Tok;
+if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
+  PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+  << PragmaName.getIdentifierInfo()->getName();
+  return;
+}
 tok::OnOffSwitch OOS;
 if (PP.LexOnOffSwitch(OOS))
  return;
@@ -2553,6 +2559,12 @@
  Token &Tok) {
   Sema::PragmaMsStackAction Action = Sema::PSK_Set;
   SourceLocation FloatControlLoc = Tok.getLocation();
+  Token PragmaName = Tok;
+  if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
+PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+<< PragmaName.getIdentifierInfo()->getName();
+return;
+  }
   PP.Lex(Tok);
   if (Tok.isNot(tok::l_paren)) {
 PP.Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
@@ -2952,6 +2964,11 @@
 Token &Tok) {
   Token PragmaName = Tok;
   SmallVector TokenList;
+  if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
+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;
+def warn_pragma_fp_ignored : Warning<
+  "'#pragma %0' is not supported on this target - ignored">,
+  InGroup;
 // - #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@+4 {{'#pragma float_control' is not supported on this target - ignored}}
+// expected-warning@+5 {{'#pragma FENV_ACCESS' is not supported on this target - ignored}}
+// expected-warning@+6 {{'#pragma FENV_ROUND' is not supported on this target 

[PATCH] D90316: [FPEnv] Diagnose pragmas FENV_ROUND,_ACCESS and float_control if target does not support StrictFP

2020-10-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/ParsePragma.cpp:107
+if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
+  PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+  << "FENV_ACCESS";

Can you fix the lint issues (run the patch through clang-format)? Same for 
below.



Comment at: clang/lib/Parse/ParsePragma.cpp:2967
+PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
+<< PragmaName.getIdentifierInfo()->getName();
+return;

Can you pass in `PragmaName` directly, or does that do unfortunate things with 
single quotes?



Comment at: clang/test/Parser/pragma-fp-warn.c:11-13
+// 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}}

I'd appreciate reversing the order of the comments so that they're in the same 
order as the pragmas below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90316

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90316: [FPEnv] Diagnose pragmas FENV_ROUND,_ACCESS and float_control if target does not support StrictFP

2020-10-28 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

In D90316#2359366 , @kpn wrote:

> I also added "-fexperimental-strict-floating-point" which makes it possible 
> to write tests for a target when bringing up the support on that target. I 
> think it would be confusing for that flag to work on command line arguments 
> but not pragmas.

Thanks, I added this


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90316

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90316: [FPEnv] Diagnose pragmas FENV_ROUND,_ACCESS and float_control if target does not support StrictFP

2020-10-28 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 301322.
mibintc added a comment.

Modified according to @kpn suggestion: if the command line has option 
fexperimental-strict-floating-point, the float pragmas will not be ignored.


Repository:
  rG LLVM Github Monorepo

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

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.getLangOpts().ExpStrictFP) {
+  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.getLangOpts().ExpStrictFP) {
+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 TokenList;
+  if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
+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;
+def warn_pragma_fp_ignored : Warning<
+  "'#pragma %0' is not supported on this target - ignored">,
+  InGroup;
 // - #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

[PATCH] D90316: [FPEnv] Diagnose pragmas FENV_ROUND,_ACCESS and float_control if target does not support StrictFP

2020-10-28 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn added a comment.

I also added "-fexperimental-strict-floating-point" which makes it possible to 
write tests for a target when bringing up the support on that target. I think 
it would be confusing for that flag to work on command line arguments but not 
pragmas.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90316

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90316: [FPEnv] Diagnose pragmas FENV_ROUND,_ACCESS and float_control if target does not support StrictFP

2020-10-28 Thread Melanie Blower via Phabricator via cfe-commits
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 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;
+def warn_pragma_fp_ignored : Warning<
+  "'#pragma %0' is not supported on this target - ignored">,
+  InGroup;
 // - #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 {{'#pragm