openmp: Actually ignore pragma_stmt pragmas for which c_parser_pragma returns false
Unlike the C++ FE, the C FE ignored pragmas (as if they weren't there) in pragma_stmt contexts if c*_parser_pragma returns false only when after labels, not inside of substatements of selection or loop statements. After making just that change, several gomp/goacc testcases started failing, because extra diagnostics has been emitted (in C, in C++ it was emitted already before). Say void foo (int x) { if (x) #pragma omp barrier } used to in C emit just an error that the pragma is not allowed in such contexts, but in C++ emitted both that and a parsing error that if (x) } is invalid. So, the rest of this patch is mostly about returning true after we report that that certain pragma is not allowed in pragma_stmt contexts, because for error-recovery it seems better to treat the pragma in that case as something that is the substatement of such if etc. c*_parser_pragma return value is only ever used for pragma_stmt context, in which false means act as if the pragma isn't there (e.g. has been handled already by preprocessor etc.), and true which means it was there. 2021-08-18 Jakub Jelinek <jakub@redhat.com> gcc/c/ * c-parser.c (c_parser_statement_after_labels): Add restart label near the start of the function. If c_parser_pragma returns false, goto restart. (c_parser_pragma): For PRAGMA_OMP_CANCELLATION_POINT return what c_parser_omp_cancellation_point returned. For PRAGMA_OMP_DECLARE return what c_parser_omp_declare returned. Return true instead of false after emitting errors that the directive is not allowed in pragma_stmt context. (c_parser_omp_ordered): Return true instead of false after emitting errors that the directive is not allowed in pragma_stmt context. (c_parser_omp_target_update): Likewise. (c_parser_omp_target_enter_data, c_parser_omp_target_exit_data): Change return type from tree to bool, return false if the directive should be ignored in pragma_stmt contexts. (c_parser_omp_target): Adjust callers of c_parser_omp_target_*_data, return their result directly. (c_parser_omp_cancellation_point): Change return type from void to bool, return false if the directive should be ignored in pragma_stmt contexts. (c_parser_omp_declare): Likewise. gcc/cp/ * parser.c (cp_parser_omp_ordered): Return true instead of false after emitting errors that the directive is not allowed in pragma_stmt context. (cp_parser_omp_target_update): Likewise. (cp_parser_omp_cancellation_point): Change return type from void to bool, return false if the directive should be ignored in pragma_stmt contexts. (cp_parser_omp_target_enter_data, cp_parser_omp_target_exit_data): Change return type from tree to bool, return false if the directive should be ignored in pragma_stmt contexts. (cp_parser_omp_target): Adjust callers of cp_parser_omp_target_*_data, return their result directly. (cp_parser_pragma): For PRAGMA_OMP_CANCELLATION_POINT return what cp_parser_omp_cancellation_point returned. Return true instead of false after emitting errors that the directive is not allowed in pragma_stmt context. gcc/testsuite/ * c-c++-common/gomp/pr63326.c: Don't expect extra "before" errors in C++. * g++.dg/gomp/attrs-7.C: Don't expect one extra error. * g++.dg/gomp/barrier-2.C: Likewise. * gcc.dg/gomp/declare-simd-5.c: Likewise. * gcc.dg/gomp/barrier-2.c: Likewise. * gcc.dg/gomp/declare-variant-2.c: Likewise.
Showing
- gcc/c/c-parser.c 35 additions, 35 deletionsgcc/c/c-parser.c
- gcc/cp/parser.c 37 additions, 25 deletionsgcc/cp/parser.c
- gcc/testsuite/c-c++-common/gomp/pr63326.c 22 additions, 22 deletionsgcc/testsuite/c-c++-common/gomp/pr63326.c
- gcc/testsuite/g++.dg/gomp/attrs-7.C 1 addition, 2 deletionsgcc/testsuite/g++.dg/gomp/attrs-7.C
- gcc/testsuite/g++.dg/gomp/barrier-2.C 1 addition, 1 deletiongcc/testsuite/g++.dg/gomp/barrier-2.C
- gcc/testsuite/gcc.dg/gomp/barrier-2.c 1 addition, 2 deletionsgcc/testsuite/gcc.dg/gomp/barrier-2.c
- gcc/testsuite/gcc.dg/gomp/declare-simd-5.c 1 addition, 1 deletiongcc/testsuite/gcc.dg/gomp/declare-simd-5.c
- gcc/testsuite/gcc.dg/gomp/declare-variant-2.c 1 addition, 1 deletiongcc/testsuite/gcc.dg/gomp/declare-variant-2.c
Loading
Please register or sign in to comment