[05/40] Fix bug in processing of array dimensions in data clauses.

Message ID 20211215155447.19379-6-frederik@codesourcery.com
State New
Headers
Series OpenACC "kernels" Improvements |

Commit Message

Frederik Harwath Dec. 15, 2021, 3:54 p.m. UTC
  From: Sandra Loosemore <sandra@codesourcery.com>

The g++ front end wraps the array length and low_bound values in
NON_LVALUE_EXPR, causing the subsequent tests for INTEGER_CST to fail.
The test case c-c++-common/goacc/kernels-loop-annotation-1.c was
tickling this bug and giving bogus errors in g++ because it was falling
through to dynamic array code instead of recognizing the constant bounds.

This patch was posted upstream here
https://gcc.gnu.org/pipermail/gcc-patches/2020-March/542694.html
but not yet committed.  It may be that some other fix for this problem
is implemented on mainline instead; check before merging this patch.

2020-03-31  Sandra Loosemore  <sandra@codesourcery.com>

        gcc/cp/
        * semantics.c (handle_omp_array_sections_1): Call STRIP_NOPS
        on length and low_bound;
        (handle_omp_array_sections): Likewise.
---
 gcc/cp/semantics.c | 9 +++++++++
 1 file changed, 9 insertions(+)

--
2.33.0

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
  

Patch

diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 2443d0327498..c2643d0a7a24 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -5145,6 +5145,10 @@  handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
   if (length)
     length = mark_rvalue_use (length);
   /* We need to reduce to real constant-values for checks below.  */
+  if (length)
+    STRIP_NOPS (length);
+  if (low_bound)
+    STRIP_NOPS (low_bound);
   if (length)
     length = fold_simple (length);
   if (low_bound)
@@ -5457,6 +5461,11 @@  handle_omp_array_sections (tree c, enum c_omp_region_type ort)
          tree low_bound = TREE_PURPOSE (t);
          tree length = TREE_VALUE (t);

+         if (length)
+           STRIP_NOPS (length);
+         if (low_bound)
+           STRIP_NOPS (low_bound);
+
          i--;
          if (low_bound
              && TREE_CODE (low_bound) == INTEGER_CST