* [committed] Reject invalid #pragma omp declare simd in the C FE
@ 2017-11-23 20:30 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2017-11-23 20:30 UTC (permalink / raw)
To: gcc-patches
Hi!
Unlike C++, C doesn't allow function declarations inside of if/while/for
body without {}s around, or after a label, while with #pragma omp declare simd
in between and -fopenmp it would happily accept it. That is wrong, the
presence/absence of OpenMP pragmas shouldn't change parsing that way.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed to trunk.
2017-11-23 Jakub Jelinek <jakub@redhat.com>
* c-parser.c (c_parser_omp_declare_simd): Reject declare simd in
pragma_stmt context.
* gcc.dg/gomp/declare-simd-1.c (f9): Remove.
* gcc.dg/gomp/declare-simd-5.c: New test.
--- gcc/c/c-parser.c.jj 2017-11-20 19:55:39.000000000 +0100
+++ gcc/c/c-parser.c 2017-11-23 17:43:51.623042138 +0100
@@ -17483,11 +17483,11 @@ c_parser_omp_declare_simd (c_parser *par
break;
case pragma_struct:
case pragma_param:
+ case pragma_stmt:
c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by "
"function declaration or definition");
break;
case pragma_compound:
- case pragma_stmt:
if (c_parser_next_token_is (parser, CPP_KEYWORD)
&& c_parser_peek_token (parser)->keyword == RID_EXTENSION)
{
--- gcc/testsuite/gcc.dg/gomp/declare-simd-1.c.jj 2016-04-06 14:46:29.000000000 +0200
+++ gcc/testsuite/gcc.dg/gomp/declare-simd-1.c 2017-11-23 17:46:04.914434577 +0100
@@ -58,18 +58,6 @@ f7 (int x)
/* { dg-final { scan-assembler-times "_ZGVeM16v_f7:" 1 { target { i?86-*-* x86_64-*-* } } } } */
/* { dg-final { scan-assembler-times "_ZGVeN16v_f7:" 1 { target { i?86-*-* x86_64-*-* } } } } */
-int
-f9 (int x)
-{
- if (x)
- #pragma omp declare simd simdlen (8) aligned (b : 8 * sizeof (int))
- extern int f10 (int a, int *b, int c);
- while (x < 10)
- #pragma omp declare simd simdlen (8) aligned (b : 8 * sizeof (int))
- extern int f11 (int a, int *b, int c);
- return x;
-}
-
#pragma omp declare simd uniform (a) aligned (b : 8 * sizeof (int)) linear (c : 4) simdlen (8)
int f12 (int c; int *b; int a; int a, int *b, int c);
--- gcc/testsuite/gcc.dg/gomp/declare-simd-5.c.jj 2017-11-23 17:47:01.886747780 +0100
+++ gcc/testsuite/gcc.dg/gomp/declare-simd-5.c 2017-11-23 17:51:10.749747753 +0100
@@ -0,0 +1,35 @@
+/* Test parsing of #pragma omp declare simd */
+/* { dg-do compile } */
+
+int
+f1 (int x)
+{
+ if (x)
+ #pragma omp declare simd simdlen (8) aligned (b : 8 * sizeof (int))
+ extern int f3 (int a, int *b, int c); /* { dg-error "must be followed by function declaration or definition" } */
+ while (x < 10)
+ #pragma omp declare simd simdlen (8) aligned (b : 8 * sizeof (int))
+ extern int f4 (int a, int *b, int c); /* { dg-error "must be followed by function declaration or definition" } */
+ {
+lab:
+ #pragma omp declare simd simdlen (8) aligned (b : 8 * sizeof (int))
+ extern int f5 (int a, int *b, int c); /* { dg-error "must be followed by function declaration or definition" } */
+ x++; /* { dg-error "expected expression before" "" { target *-*-* } .-1 } */
+ }
+ return x;
+}
+
+int
+f2 (int x)
+{
+ if (x)
+ extern int f6 (int a, int *b, int c); /* { dg-error "expected expression before" } */
+ while (x < 10)
+ extern int f7 (int a, int *b, int c); /* { dg-error "expected expression before" } */
+ {
+lab:
+ extern int f8 (int a, int *b, int c); /* { dg-error "a label can only be part of a statement and a declaration is not a statement" } */
+ x++;
+ }
+ return x;
+}
Jakub
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-11-23 20:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-23 20:30 [committed] Reject invalid #pragma omp declare simd in the C FE Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).