Good evening,

This is my first patch with the intention of solving
a bug (namely, libgomp/125691). It seems like a
regression from 53891f18, in which the cp_parser_omp_loop
stopped returning NULL directly when parenthesis were
not found.  My fix is simply to do so in the least
intrusive way possible.


I can confirm I have stepped through the code, diagnosed
the error, patched, recompiled (& bootstrapped), verified
that it did not crash anymore, and made a simple test to
cover it.

However, I did not run the full c/c++ test suite, and
from the tests I did run,  I notice some possibly
unrelated error messages.

So this seems like a good place to ask for guidance:

(1) For such patches, should I always boostrap + run all
  C and C++ tests? I see that 'guality' tests are failing
  on my machine and it seems to happen fairly frequently
  in the mailing list.

(2) Also, for this patch specifically, should the test
  file be located in "g++.dg" or in "c-c++-common"?
  Since the 'for' keyword might indicate a 'c-style'
  for or a 'range-for' in C++, perhaps the test is
  complete being just in the c++ folder.

In any case, thank you very much for your time.
See patch message below,

Best regards,
Léo

---

When no parenthesis were found after the 'for' keyword,
NULL was returned but the caller wasn't checking for
NULL, so GCC failed in the next assert. The solution
was to set the 'fail' flag to true before returning.

This ICE only happened when the -fopenmp argument was
passed.

        PR libgomp/125691

gcc/cp/ChangeLog:

        * parser.cc (cp_parser_omp_loop_nest): Set failure when
        returning NULL. Fixes refactoring regression on 53891f18.

gcc/testsuite/ChangeLog:

        * g++.dg/gomp/pr125691.C: New test.

Signed-off-by: Léo Hardt <[email protected]>
---
 gcc/cp/parser.cc                     |  5 ++++-
 gcc/testsuite/g++.dg/gomp/pr125691.C | 25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/gomp/pr125691.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 3f042bec1c6..d544f8ba41f 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -49802,7 +49802,10 @@ cp_parser_omp_loop_nest (cp_parser *parser, bool *if_p)

   matching_parens parens;
   if (!parens.require_open (parser))
-    return NULL;
+    {
+      omp_for_parse_state->fail = true;
+      return NULL_TREE;
+    }

   init_placeholder = build_stmt (input_location, EXPR_STMT,
                                 integer_zero_node);
diff --git a/gcc/testsuite/g++.dg/gomp/pr125691.C b/gcc/testsuite/g++.dg/gomp/pr125691.C
new file mode 100644
index 00000000000..06acb3c61cf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/pr125691.C
@@ -0,0 +1,25 @@
+/* { dg-require-effective-target fopenmp } */
+/* { dg-additional-options "-fopenmp -Wall" } */
+
+void f1_simd(){
+  #pragma omp simd
+  for; /* { dg-error {expected '\(' before} } */
+}
+
+void f2_simd(){
+  int i;
+  #pragma omp simd
+  for i = 0; /* { dg-error {expected '\(' before} } */
+}
+
+
+void f1_for(){
+  #pragma omp for
+  for; /* { dg-error {expected '\(' before} } */
+}
+
+void f2_for(){
+  int i;
+  #pragma omp for
+  for i = 0; /* { dg-error {expected '\(' before} } */
+}
--
2.39.5


Reply via email to