aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Basic/DiagnosticParseKinds.td4
-rw-r--r--lib/Parse/ParseStmt.cpp11
-rw-r--r--test/CodeGen/fp-contract-pragma.cpp1
-rw-r--r--test/Parser/pragma-fp-contract.c6
4 files changed, 18 insertions, 4 deletions
diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td
index b670d6e8cb..e01cdb77e5 100644
--- a/include/clang/Basic/DiagnosticParseKinds.td
+++ b/include/clang/Basic/DiagnosticParseKinds.td
@@ -729,6 +729,10 @@ def warn_pragma_unused_expected_var : Warning<
"expected '#pragma unused' argument to be a variable name">;
def warn_pragma_unused_expected_punc : Warning<
"expected ')' or ',' in '#pragma unused'">;
+// - #pragam fp_contract
+def err_pragma_fp_contract_scope : Error<
+ "'#pragma fp_contract' should only appear at file scope or at the start of a "
+ "compound expression">;
// OpenCL Section 6.8.g
def err_not_opencl_storage_class_specifier : Error<
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index d008b037b0..964240df08 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -280,9 +280,10 @@ Retry:
return StmtEmpty();
case tok::annot_pragma_fp_contract:
- ProhibitAttributes(Attrs);
- HandlePragmaFPContract();
- return StmtEmpty();
+ Diag(Tok, diag::err_pragma_fp_contract_scope);
+ ConsumeToken();
+ return StmtError();
+
case tok::annot_pragma_opencl_extension:
ProhibitAttributes(Attrs);
@@ -728,6 +729,10 @@ StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {
StmtVector Stmts;
+ // Parse FP_CONTRACT if present.
+ if (Tok.is(tok::annot_pragma_fp_contract))
+ HandlePragmaFPContract();
+
// "__label__ X, Y, Z;" is the GNU "Local Label" extension. These are
// only allowed at the start of a compound stmt regardless of the language.
while (Tok.is(tok::kw___label__)) {
diff --git a/test/CodeGen/fp-contract-pragma.cpp b/test/CodeGen/fp-contract-pragma.cpp
index edb04d82ef..afd8c43121 100644
--- a/test/CodeGen/fp-contract-pragma.cpp
+++ b/test/CodeGen/fp-contract-pragma.cpp
@@ -39,7 +39,6 @@ template<typename T> class fp_contract_4 {
float method(float a, float b, float c) {
#pragma STDC FP_CONTRACT ON
return a * b + c;
- #pragma STDC FP_CONTRACT OFF
}
};
diff --git a/test/Parser/pragma-fp-contract.c b/test/Parser/pragma-fp-contract.c
new file mode 100644
index 0000000000..619053f465
--- /dev/null
+++ b/test/Parser/pragma-fp-contract.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void f1(void) {
+ int x = 0;
+/* expected-error {{'#pragma fp_contract' should only appear at file scope or at the start of a compound expression}} */ #pragma STDC FP_CONTRACT ON
+}