[clang] 13bfd89 - [clang][FPEnv] Diagnose Strict FP pragmas if target does not support StrictFP
Melanie Blower via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 30 06:12:55 PDT 2020
Author: Melanie Blower
Date: 2020-10-30T06:11:25-07:00
New Revision: 13bfd89c4962e738cbe50662013267b33a678b8f
URL: https://github.com/llvm/llvm-project/commit/13bfd89c4962e738cbe50662013267b33a678b8f
DIFF: https://github.com/llvm/llvm-project/commit/13bfd89c4962e738cbe50662013267b33a678b8f.diff
LOG: [clang][FPEnv] Diagnose Strict FP pragmas if target does not support StrictFP
Reviewers: sepavloff, kpn, aaron.ballman
Differential Revision: https://reviews.llvm.org/D90316
Added:
clang/test/Parser/pragma-fp-warn.c
Modified:
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParsePragma.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 24ca8340ef6f..0fd4eb5323de 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1147,6 +1147,9 @@ def warn_stdc_fenv_round_not_supported :
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">;
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 36bfeeebfef3..278e6f50deba 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -103,6 +103,12 @@ struct PragmaSTDC_FENV_ACCESSHandler : public PragmaHandler {
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 @@ void PragmaFloatControlHandler::HandlePragma(Preprocessor &PP,
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 @@ void PragmaSTDC_FENV_ROUNDHandler::HandlePragma(Preprocessor &PP,
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)) {
diff --git a/clang/test/Parser/pragma-fp-warn.c b/clang/test/Parser/pragma-fp-warn.c
new file mode 100644
index 000000000000..21a2cccf4d8f
--- /dev/null
+++ b/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
More information about the cfe-commits
mailing list