For -fopenmp-simd, GCC did not properly jump passed the clauses of ignored directives. It worked, for "for simd" directives and for those without clauses.
Bootstrapped and regtested on x86-64-gnu-linux. OK for the trunk? Tobias
2015-03-28 Tobias Burnus <bur...@net-b.de> PR c/65586 gcc/c/ * c-parser.c (c_parser_skip_to_pragma_eol): Optionally, don't error out. (c_parser_omp_for, c_parser_omp_parallel, c_parser_omp_distribute, c_parser_omp_teams, c_parser_omp_target, c_parser_omp_declare): Update calls to not error for skipped omp pragmas with -fopenmp-simd. gcc/cp/ * parser.c (cp_parser_omp_for, cp_parser_omp_parallel, cp_parser_omp_distribute, cp_parser_omp_teams, cp_parser_omp_target, cp_parser_omp_declare): Don't show error for skipped omp pragmas with -fopenmp-simd. gcc/testsuite/ * g++.dg/gomp/openmp-simd-3.C: New. * gcc.dg/gomp/openmp-simd-3.c: New. diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 5cc3892..18faa6e 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -991,24 +991,26 @@ c_parser_skip_to_end_of_parameter (c_parser *parser) end of line marker. */ static void -c_parser_skip_to_pragma_eol (c_parser *parser) +c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true) { gcc_assert (parser->in_pragma); parser->in_pragma = false; - if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line")) - while (true) - { - c_token *token = c_parser_peek_token (parser); - if (token->type == CPP_EOF) + if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL) + c_parser_error (parser, "expected end of line"); + + while (true) + { + c_token *token = c_parser_peek_token (parser); + if (token->type == CPP_EOF) + break; + if (token->type == CPP_PRAGMA_EOL) + { + c_parser_consume_token (parser); break; - if (token->type == CPP_PRAGMA_EOL) - { - c_parser_consume_token (parser); - break; - } - c_parser_consume_token (parser); - } + } + c_parser_consume_token (parser); + } parser->error = false; } @@ -13223,7 +13225,7 @@ c_parser_omp_for (location_t loc, c_parser *parser, } if (!flag_openmp) /* flag_openmp_simd */ { - c_parser_skip_to_pragma_eol (parser); + c_parser_skip_to_pragma_eol (parser, false); return NULL_TREE; } @@ -13448,7 +13450,7 @@ c_parser_omp_parallel (location_t loc, c_parser *parser, } else if (!flag_openmp) /* flag_openmp_simd */ { - c_parser_skip_to_pragma_eol (parser); + c_parser_skip_to_pragma_eol (parser, false); return NULL_TREE; } else if (c_parser_next_token_is (parser, CPP_NAME)) @@ -13708,7 +13710,7 @@ c_parser_omp_distribute (location_t loc, c_parser *parser, } if (!flag_openmp) /* flag_openmp_simd */ { - c_parser_skip_to_pragma_eol (parser); + c_parser_skip_to_pragma_eol (parser, false); return NULL_TREE; } @@ -13776,7 +13778,7 @@ c_parser_omp_teams (location_t loc, c_parser *parser, } if (!flag_openmp) /* flag_openmp_simd */ { - c_parser_skip_to_pragma_eol (parser); + c_parser_skip_to_pragma_eol (parser, false); return NULL_TREE; } @@ -13921,7 +13923,7 @@ c_parser_omp_target (c_parser *parser, enum pragma_context context) } else if (!flag_openmp) /* flag_openmp_simd */ { - c_parser_skip_to_pragma_eol (parser); + c_parser_skip_to_pragma_eol (parser, false); return false; } else if (strcmp (p, "data") == 0) @@ -14604,7 +14606,7 @@ c_parser_omp_declare (c_parser *parser, enum pragma_context context) } if (!flag_openmp) /* flag_openmp_simd */ { - c_parser_skip_to_pragma_eol (parser); + c_parser_skip_to_pragma_eol (parser, false); return; } if (strcmp (p, "target") == 0) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index a18f38c..4d6b479 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -30768,7 +30768,7 @@ cp_parser_omp_for (cp_parser *parser, cp_token *pragma_tok, } if (!flag_openmp) /* flag_openmp_simd */ { - cp_parser_require_pragma_eol (parser, pragma_tok); + cp_parser_skip_to_pragma_eol (parser, pragma_tok); return NULL_TREE; } @@ -30979,7 +30979,7 @@ cp_parser_omp_parallel (cp_parser *parser, cp_token *pragma_tok, } else if (!flag_openmp) /* flag_openmp_simd */ { - cp_parser_require_pragma_eol (parser, pragma_tok); + cp_parser_skip_to_pragma_eol (parser, pragma_tok); return NULL_TREE; } else if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)) @@ -31242,7 +31242,7 @@ cp_parser_omp_distribute (cp_parser *parser, cp_token *pragma_tok, } if (!flag_openmp) /* flag_openmp_simd */ { - cp_parser_require_pragma_eol (parser, pragma_tok); + cp_parser_skip_to_pragma_eol (parser, pragma_tok); return NULL_TREE; } @@ -31321,7 +31321,7 @@ cp_parser_omp_teams (cp_parser *parser, cp_token *pragma_tok, } if (!flag_openmp) /* flag_openmp_simd */ { - cp_parser_require_pragma_eol (parser, pragma_tok); + cp_parser_skip_to_pragma_eol (parser, pragma_tok); return NULL_TREE; } @@ -31466,7 +31466,7 @@ cp_parser_omp_target (cp_parser *parser, cp_token *pragma_tok, } else if (!flag_openmp) /* flag_openmp_simd */ { - cp_parser_require_pragma_eol (parser, pragma_tok); + cp_parser_skip_to_pragma_eol (parser, pragma_tok); return false; } else if (strcmp (p, "data") == 0) @@ -32442,7 +32442,7 @@ cp_parser_omp_declare (cp_parser *parser, cp_token *pragma_tok, } if (!flag_openmp) /* flag_openmp_simd */ { - cp_parser_require_pragma_eol (parser, pragma_tok); + cp_parser_skip_to_pragma_eol (parser, pragma_tok); return; } if (strcmp (p, "target") == 0) diff --git a/gcc/testsuite/g++.dg/gomp/openmp-simd-3.C b/gcc/testsuite/g++.dg/gomp/openmp-simd-3.C new file mode 100644 index 0000000..eba9de2 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/openmp-simd-3.C @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-fopenmp-simd -fdump-tree-original" } */ + +/* PR c/65586 */ + +void foo() { } + +int main() { +#pragma omp for collapse(1) + for (int i = 1; i <= 151; i+=31) + foo(); +} + +/* { dg-final { scan-tree-dump-not "omp" "original" } } */ +/* { dg-final { cleanup-tree-dump "original" } } */ diff --git a/gcc/testsuite/gcc.dg/gomp/openmp-simd-3.c b/gcc/testsuite/gcc.dg/gomp/openmp-simd-3.c new file mode 100644 index 0000000..eba9de2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gomp/openmp-simd-3.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-fopenmp-simd -fdump-tree-original" } */ + +/* PR c/65586 */ + +void foo() { } + +int main() { +#pragma omp for collapse(1) + for (int i = 1; i <= 151; i+=31) + foo(); +} + +/* { dg-final { scan-tree-dump-not "omp" "original" } } */ +/* { dg-final { cleanup-tree-dump "original" } } */