[PATCH] D90316: [FPEnv] Diagnose pragmas FENV_ROUND,_ACCESS and float_control if target does not support StrictFP
Melanie Blower via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 29 12:21:58 PDT 2020
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 at +4 {{'#pragma float_control' is not supported on this target - ignored}}
+// expected-warning at +5 {{'#pragma FENV_ACCESS' is not supported on this target - ignored}}
+// expected-warning at +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<Token, 1> 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<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">;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90316.301708.patch
Type: text/x-patch
Size: 3531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201029/1e15b97e/attachment.bin>
More information about the cfe-commits
mailing list