From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1709) id B2DF83858C74; Thu, 27 Jan 2022 10:35:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2DF83858C74 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Chung-Lin Tang To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6890] Fix omp-low ICE for indirect references based off component access [PR103642] X-Act-Checkin: gcc X-Git-Author: Chung-Lin Tang X-Git-Refname: refs/heads/master X-Git-Oldrev: 2e4bf373f2ae97be3adc654054e7e8a982813766 X-Git-Newrev: 1c91b014923f418e0aab789c5cf57facf04bf266 Message-Id: <20220127103557.B2DF83858C74@sourceware.org> Date: Thu, 27 Jan 2022 10:35:57 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jan 2022 10:35:57 -0000 https://gcc.gnu.org/g:1c91b014923f418e0aab789c5cf57facf04bf266 commit r12-6890-g1c91b014923f418e0aab789c5cf57facf04bf266 Author: Chung-Lin Tang Date: Thu Jan 27 18:33:00 2022 +0800 Fix omp-low ICE for indirect references based off component access [PR103642] This issue was triggered after the patch extending syntax for component access in map clauses in commit 0ab29cf0bb68960c1f87405f14b4fb2109254e2f. In gimplify_scan_omp_clauses, the case for handling indirect accesses (which creates firstprivate ptr and zero-length array section map for such decls) was erroneously went into for non-pointer cases (here being the base struct decl), so added the appropriate checks there. Added new testcase is a compile only test for the ICE. The original omptests t-partial-struct test actually should not execute correctly, because for map(t.s->a[:N]), map(t.s[:1]) is not implicitly mapped, thus the entire offloaded access does not work as is (fixing that omptests test is out of scope here). 2022-01-27 Chung-Lin Tang PR middle-end/103642 gcc/ChangeLog: * gimplify.cc (gimplify_scan_omp_clauses): Do not do indir_p handling for non-pointer or non-reference-to-pointer cases. gcc/testsuite/ChangeLog: * c-c++-common/gomp/pr103642.c: New test. Diff: --- gcc/gimplify.cc | 5 ++++- gcc/testsuite/c-c++-common/gomp/pr103642.c | 34 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index bf2f60cce9a..cd4b61362b4 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -9552,7 +9552,10 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, == REFERENCE_TYPE)) decl = TREE_OPERAND (decl, 0); } - if (decl != orig_decl && DECL_P (decl) && indir_p) + if (decl != orig_decl && DECL_P (decl) && indir_p + && (TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE + || (decl_ref + && TREE_CODE (TREE_TYPE (decl_ref)) == POINTER_TYPE))) { gomp_map_kind k = ((code == OACC_EXIT_DATA || code == OMP_TARGET_EXIT_DATA) diff --git a/gcc/testsuite/c-c++-common/gomp/pr103642.c b/gcc/testsuite/c-c++-common/gomp/pr103642.c new file mode 100644 index 00000000000..bbd0896841f --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/pr103642.c @@ -0,0 +1,34 @@ +/* PR middle-end/103642 */ +/* { dg-do compile } */ + +#include + +typedef struct +{ + int *a; +} S; + +typedef struct +{ + S *s; + int *ptr; +} T; + +#define N 10 + +int main (void) +{ + T t; + t.s = (S *) malloc (sizeof (S)); + t.s->a = (int *) malloc (sizeof(int) * N); + + #pragma omp target map(from: t.s->a[:N]) + { + t.s->a[0] = 1; + } + + free (t.s->a); + free (t.s); + + return 0; +}