On Wed, 9 Sep 2026, Tobias Burnus wrote:

> Seehttps://gcc.gnu.org/PR127273 for some background.
> 
> This fixes an ICE with OpenMP 'link' variable where the offload
> compile changes such static variables to be variable of pointer
> type of the host variable.
> 
> This failed as no varpool_node was available when needed and,
> as for some reason, the same decl appeared multiple times
> in the FOR_EACH_VARIABLE loop. - For some reasons, and possibly
> related to VALUE_EXPR, IPA also decided that it could remove that
> node - even though it was used. (It worked at -O0)

Well, because you add variables by creating a varpool node
while looping over the symtab?  I don't think this is safe.
May I suggest to create a worklist for the varpool creation part?

Otherwise, well, I suppose it makes sense.

> 
> 
> Question to more LTO/IPA savor developers: Does this patch look
> right? It surely fixes the issue... And other comments before I
> commit it?
> 
> * * *
> 
> Other issues related to 'link', but of different nature:
> * PR 127214 and PR 127213 (still to be investigated; one
>   issue is quite different, the other relates to having
>   static 'link' variable at function scope; I am not quite
>   sure it is properly handled, but at least some usage is
>   working as libgomp.fortran/declare-target-link.f90 tests it.)
> [There might be other issues as well.]
> 
> * * *
> 
> Background about the 'link' feature:
> 
> int var[1024];
> #pragma omp declare target link(var)
> 
> 'link' has two purposes: The older one is to permit only partially
> mapping data on the device to save memory. Such as only
> mapping  'var[200:10]', i.e. element index 200 and 9 following
> elements (i.e. length = 10).
> This works by having not 'int var[1024]' on the device side but
> 'int *var$linkptr' – and replacing (VALUE_EXPR) all access by
> to 'var' by '*var%linkptr'.
> 
> The newer purpose (I ran into): with 'requires self_maps',
> the device side is supposed to access the host pointer such
> it uses 'link' internally and libgomp initializes the device
> side to point to the host variable.
> 
> Cheers,
> 
> Tobias
> 
> 

-- 
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Jochen Jaser, Andrew McDonald, Abhinav Puri; (HRB 36809, AG Nuernberg)

Reply via email to