https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127273

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tobias Burnus <[email protected]>:

https://gcc.gnu.org/g:a6310d58aac505bdea37a6a0d6ab6b9593d01259

commit r17-4073-ga6310d58aac505bdea37a6a0d6ab6b9593d01259
Author: Tobias Burnus <[email protected]>
Date:   Thu Sep 10 13:25:39 2026 +0200

    lto.cc: OpenMP's offload_handle_link_vars - fix for global variables
[PR127273]

    This is about variables that appear in OpenMP's 'link' clause of
    the 'declare target' directive. On the host, they are normal
    static variables - while on the device, they are pointer variables
    that point to the actual data, i.e. the access 'var' on the host
    becomes '* var$linkptr' on the device side, using a VALUE_EXPR
    to achieve this.  The offload_handle_link_vars handles this
    ('#if ACCEL_COMPILER').

    For global variables, additional issues occurred:
    * The function would be called multiple times for the same variable
      each time calling 'build_decl' again.
      Solution: If there is already a VALUE_EXPR, skip.
    * Some code, in particular ipa_reference_var_uid assumes that also
      decl->decl_with_vis.symtab_node is not NULL.
      Solution: Call varpool_node::finalize_decl to create it.
    * For some reasons some IPA analysis assumes that it is not needed
      and, hence, the node can be removed, which fails (see previous item).
      Solution: Use force_output.

    As global static variables have to be output via the offload_vars,
    the host and device side need to exist to make sure the n-th variable
    in the host table is the same as the n-th variable on the device side,
    i.e. forcing the output makes sense.

            PR middle-end/127273

    gcc/lto/ChangeLog:

            * lto.cc (offload_handle_link_vars): Create node and force_output;
            avoid creating the same '...$linkptr' var multiple times.

    libgomp/ChangeLog:

            * testsuite/libgomp.c/usm_env_handling-1-self.c: Remove 'dg-ice'.

Reply via email to