diff mbox

pr 60211 - error out if ivdep pragma is outside a function

Message ID 1421721234-7228-1-git-send-email-tbsaunde+gcc@tbsaunde.org
State New
Headers show

Commit Message

tbsaunde+gcc@tbsaunde.org Jan. 20, 2015, 2:33 a.m. UTC
From: Trevor Saunders <tbsaunde+gcc@tbsaunde.org>

Hi,

not doing $subject caused ICES when we tried to parse statements outside of
functions.  Just copy the similar code for other pragmas that effect
statements.


bootstrapped + regtested x86_64-linux-gnu, ok?

Trev
diff mbox

Patch

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f60141d..d9c3ad6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@ 
+2015-01-18  Trevor Saunders  <tsaunders@mozilla.com>
+
+	* parser.c (cp_parser_pragma): Check if ivdep pragma is within a
+	function.
+
 2015-01-09  Michael Collison  <michael.collison@linaro.org>
 
 	* call.c: Include hash-set.h, machmode.h, vec.h, double-int.h,
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 3290dfa..4f02a65 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -32202,6 +32202,13 @@  cp_parser_pragma (cp_parser *parser, enum pragma_context context)
 
     case PRAGMA_IVDEP:
       {
+	if (context == pragma_external)
+	  {
+	    error_at (pragma_tok->location,
+		      "%<#pragma GCC ivdep%> must be inside a function");
+	    break;
+	  }
+
 	cp_parser_skip_to_pragma_eol (parser, pragma_tok);
 	cp_token *tok;
 	tok = cp_lexer_peek_token (the_parser->lexer);
diff --git a/gcc/testsuite/g++.dg/pr60211.C b/gcc/testsuite/g++.dg/pr60211.C
new file mode 100644
index 0000000..f00e644
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr60211.C
@@ -0,0 +1,11 @@ 
+// { dg-do compile }
+void foo() {}
+int x;
+#pragma GCC ivdep // { dg-error "must be inside a function" }
+for ( ; ) // { dg-error "expected unqualified-id before" }
+  ;
+
+  void baz() {}
+#pragma GCC ivdep // { dg-error "must be inside a function" }
+  for (int x = 0; ) // { dg-error "expected unqualified-id before" }
+  ;