From c99cdcab4f1c497a872cf552138fd8ea27e9a5eb Mon Sep 17 00:00:00 2001 From: Tobias Burnus Date: Thu, 1 Aug 2024 09:06:32 +0200 Subject: [PATCH] omp-offload.cc: Fix value-expr handling of 'declare target link' vars [PR115637] As the PR and included testcase shows, replacing 'arr2' by its value expression '*arr2$13$linkptr' failed for MEM [(c_char * {ref-all})&arr2] which left 'arr2' in the code as unknown symbol. Now expand the value expression already in pass_omp_target_link::execute's process_link_var_op walk_gimple_stmt walk - and don't rely on gimple_regimplify_operands. PR middle-end/115637 gcc/ChangeLog: * gimplify.cc (gimplify_body): Fix macro name in the comment. * omp-offload.cc (find_link_var_op): Rename to ... (process_link_var_op): ... this. Replace value expr. (pass_omp_target_link::execute): Update walk_gimple_stmt call. libgomp/ChangeLog: * testsuite/libgomp.fortran/declare-target-link.f90: Uncomment now working code. Co-authored-by: Richard Biener info = *tp = unshare_expr (DECL_VALUE_EXPR (t)); *walk_subtrees = 0; - return t; + return NULL_TREE; } return NULL_TREE; @@ -2924,7 +2926,10 @@ pass_omp_target_link::execute (function *fun) gimple_call_set_arg (gsi_stmt (gsi), 1, null_pointer_node); update_stmt (gsi_stmt (gsi)); } - if (walk_gimple_stmt (&gsi, NULL, find_link_var_op, NULL)) + struct walk_stmt_info wi; + memset (&wi, 0, sizeof (wi)); + walk_gimple_stmt (&gsi, NULL, process_link_var_op, &wi); + if (wi.info) gimple_regimplify_operands (gsi_stmt (gsi), &gsi); } } diff --git a/libgomp/testsuite/libgomp.fortran/declare-target-link.f90 b/libgomp/testsuite/libgomp.fortran/declare-target-link.f90 index 2ce212d114f..44c67f925bd 100644 --- a/libgomp/testsuite/libgomp.fortran/declare-target-link.f90 +++ b/libgomp/testsuite/libgomp.fortran/declare-target-link.f90 @@ -1,5 +1,7 @@ ! { dg-additional-options "-Wall" } + ! PR fortran/115559 +! PR middle-end/115637 module m integer :: A @@ -73,24 +75,19 @@ contains !$omp target map(from:res) res = run_device1() !$omp end target - print *, res - ! FIXME: arr2 not link mapped -> PR115637 - ! if (res /= -11436) stop 5 - if (res /= -11546) stop 5 ! FIXME + ! print *, res + if (res /= -11436) stop 5 end integer function run_device1() !$omp declare target integer :: i run_device1 = -99 - ! FIXME: arr2 not link mapped -> PR115637 - ! arr2 = [11,22,33,44] + arr2 = [11,22,33,44] if (any (arr(10:50) /= [(i, i=10,50)])) then run_device1 = arr(11) return end if - ! FIXME: -> PR115637 - ! run_device1 = sum(arr(10:13) + arr2) - run_device1 = sum(arr(10:13) ) ! FIXME + run_device1 = sum(arr(10:13) + arr2) do i = 10, 50 arr(i) = 3 - 10 * arr(i) end do