aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorTobias Burnus <tobias@codesourcery.com>2023-04-25 16:29:14 +0200
committerTobias Burnus <tobias@codesourcery.com>2023-04-25 16:29:14 +0200
commit1c101fcfaac8f609d618f83b124bd50aea012132 (patch)
treedd1ac83cab1561d60c15f2083fcc243b452636a8 /gcc/c
parent78aaaf862e70cea45f3a2be7cb855cfe1a4ead21 (diff)
downloadgcc-1c101fcfaac8f609d618f83b124bd50aea012132.zip
gcc-1c101fcfaac8f609d618f83b124bd50aea012132.tar.gz
gcc-1c101fcfaac8f609d618f83b124bd50aea012132.tar.bz2
'omp scan' struct block seq update for OpenMP 5.x
While OpenMP 5.0 required a single structured block before and after the 'omp scan' directive, OpenMP 5.1 changed this to a 'structured block sequence, denoting 2 or more executable statements in OpenMP 5.1 (whoops!) and zero or more in OpenMP 5.2. This commit updates C/C++ to accept zero statements (but till requires the '{' ... '}' for the final-loop-body) and updates Fortran to accept zero or more than one statements. If there is no preceeding or succeeding executable statement, a warning is shown. gcc/c/ChangeLog: * c-parser.cc (c_parser_omp_scan_loop_body): Handle zero exec statements before/after 'omp scan'. gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_scan_loop_body): Handle zero exec statements before/after 'omp scan'. gcc/fortran/ChangeLog: * openmp.cc (gfc_resolve_omp_do_blocks): Handle zero or more than one exec statements before/after 'omp scan'. * trans-openmp.cc (gfc_trans_omp_do): Likewise. libgomp/ChangeLog: * testsuite/libgomp.c-c++-common/scan-1.c: New test. * testsuite/libgomp.c/scan-23.c: New test. * testsuite/libgomp.fortran/scan-2.f90: New test. gcc/testsuite/ChangeLog: * g++.dg/gomp/attrs-7.C: Update dg-error/dg-warning. * gfortran.dg/gomp/loop-2.f90: Likewise. * gfortran.dg/gomp/reduction5.f90: Likewise. * gfortran.dg/gomp/reduction6.f90: Likewise. * gfortran.dg/gomp/scan-1.f90: Likewise. * gfortran.dg/gomp/taskloop-2.f90: Likewise. * c-c++-common/gomp/scan-6.c: New test. * gfortran.dg/gomp/scan-8.f90: New test.
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/c-parser.cc22
1 files changed, 20 insertions, 2 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 21bc316..9398c7a 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -20112,6 +20112,7 @@ c_parser_omp_scan_loop_body (c_parser *parser, bool open_brace_parsed)
tree substmt;
location_t loc;
tree clauses = NULL_TREE;
+ bool found_scan = false;
loc = c_parser_peek_token (parser)->location;
if (!open_brace_parsed
@@ -20122,7 +20123,15 @@ c_parser_omp_scan_loop_body (c_parser *parser, bool open_brace_parsed)
return;
}
- substmt = c_parser_omp_structured_block_sequence (parser, PRAGMA_OMP_SCAN);
+ if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SCAN)
+ substmt = c_parser_omp_structured_block_sequence (parser, PRAGMA_OMP_SCAN);
+ else
+ {
+ warning_at (c_parser_peek_token (parser)->location, 0,
+ "%<#pragma omp scan%> with zero preceding executable "
+ "statements");
+ substmt = build_empty_stmt (loc);
+ }
substmt = build2 (OMP_SCAN, void_type_node, substmt, NULL_TREE);
SET_EXPR_LOCATION (substmt, loc);
add_stmt (substmt);
@@ -20131,6 +20140,7 @@ c_parser_omp_scan_loop_body (c_parser *parser, bool open_brace_parsed)
if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SCAN)
{
enum omp_clause_code clause = OMP_CLAUSE_ERROR;
+ found_scan = true;
c_parser_consume_pragma (parser);
@@ -20160,7 +20170,15 @@ c_parser_omp_scan_loop_body (c_parser *parser, bool open_brace_parsed)
error ("expected %<#pragma omp scan%>");
clauses = c_finish_omp_clauses (clauses, C_ORT_OMP);
- substmt = c_parser_omp_structured_block_sequence (parser, PRAGMA_NONE);
+ if (!c_parser_next_token_is (parser, CPP_CLOSE_BRACE))
+ substmt = c_parser_omp_structured_block_sequence (parser, PRAGMA_NONE);
+ else
+ {
+ if (found_scan)
+ warning_at (loc, 0, "%<#pragma omp scan%> with zero succeeding "
+ "executable statements");
+ substmt = build_empty_stmt (loc);
+ }
substmt = build2 (OMP_SCAN, void_type_node, substmt, clauses);
SET_EXPR_LOCATION (substmt, loc);
add_stmt (substmt);