Skip to content

Commit 13bfd89

Browse files
author
Melanie Blower
committed
[clang][FPEnv] Diagnose Strict FP pragmas if target does not support StrictFP
Reviewers: sepavloff, kpn, aaron.ballman Differential Revision: https://reviews.llvm.org/D90316
1 parent f507aa1 commit 13bfd89

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,9 @@ def warn_stdc_fenv_round_not_supported :
11471147
def warn_stdc_unknown_rounding_mode : Warning<
11481148
"invalid or unsupported rounding mode in '#pragma STDC FENV_ROUND' - ignored">,
11491149
InGroup<IgnoredPragmas>;
1150+
def warn_pragma_fp_ignored : Warning<
1151+
"'#pragma %0' is not supported on this target - ignored">,
1152+
InGroup<IgnoredPragmas>;
11501153
// - #pragma comment
11511154
def err_pragma_comment_malformed : Error<
11521155
"pragma comment requires parenthesized identifier and optional string">;

clang/lib/Parse/ParsePragma.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ struct PragmaSTDC_FENV_ACCESSHandler : public PragmaHandler {
103103

104104
void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
105105
Token &Tok) override {
106+
Token PragmaName = Tok;
107+
if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
108+
PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
109+
<< PragmaName.getIdentifierInfo()->getName();
110+
return;
111+
}
106112
tok::OnOffSwitch OOS;
107113
if (PP.LexOnOffSwitch(OOS))
108114
return;
@@ -2553,6 +2559,12 @@ void PragmaFloatControlHandler::HandlePragma(Preprocessor &PP,
25532559
Token &Tok) {
25542560
Sema::PragmaMsStackAction Action = Sema::PSK_Set;
25552561
SourceLocation FloatControlLoc = Tok.getLocation();
2562+
Token PragmaName = Tok;
2563+
if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
2564+
PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
2565+
<< PragmaName.getIdentifierInfo()->getName();
2566+
return;
2567+
}
25562568
PP.Lex(Tok);
25572569
if (Tok.isNot(tok::l_paren)) {
25582570
PP.Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
@@ -2952,6 +2964,11 @@ void PragmaSTDC_FENV_ROUNDHandler::HandlePragma(Preprocessor &PP,
29522964
Token &Tok) {
29532965
Token PragmaName = Tok;
29542966
SmallVector<Token, 1> TokenList;
2967+
if (!PP.getTargetInfo().hasStrictFP() && !PP.getLangOpts().ExpStrictFP) {
2968+
PP.Diag(Tok.getLocation(), diag::warn_pragma_fp_ignored)
2969+
<< PragmaName.getIdentifierInfo()->getName();
2970+
return;
2971+
}
29552972

29562973
PP.Lex(Tok);
29572974
if (Tok.isNot(tok::identifier)) {

clang/test/Parser/pragma-fp-warn.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
// RUN: %clang_cc1 -triple wasm32 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
3+
// RUN: %clang_cc1 -triple thumbv7 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
4+
// RUN: %clang_cc1 -triple aarch64 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
5+
// RUN: %clang_cc1 -DEXPOK -triple x86_64 -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
6+
// RUN: %clang_cc1 -DEXPOK -triple systemz -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
7+
// RUN: %clang_cc1 -DEXPOK -triple powerpc -fsyntax-only -Wno-unknown-pragmas -Wignored-pragmas -verify %s
8+
#ifdef EXPOK
9+
// expected-no-diagnostics
10+
#else
11+
// expected-warning@+4 {{'#pragma float_control' is not supported on this target - ignored}}
12+
// expected-warning@+5 {{'#pragma FENV_ACCESS' is not supported on this target - ignored}}
13+
// expected-warning@+6 {{'#pragma FENV_ROUND' is not supported on this target - ignored}}
14+
#endif
15+
#pragma float_control(precise, on)
16+
17+
#pragma STDC FENV_ACCESS OFF
18+
19+
#pragma STDC FENV_ROUND FE_DOWNWARD

0 commit comments

Comments
 (0)