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

--- Comment #6 from rguenther at suse dot de <rguenther at suse dot de> ---
On Mon, 27 Nov 2023, muecker at gwdg dot de wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112716
> 
> --- Comment #5 from Martin Uecker <muecker at gwdg dot de> ---
> It works (and is required to work) for other types, e.g.
> 
> [[gnu::noinline,gnu::noipa]]
> int foo(void *p, void *q)
> {
>         int n = 5;
>         int (*p2)[n] = p;
>         (*p2)[0] = 1;
>         bar(q);
>         return (*p2)[0];
> }
> 
> void bar(void* q)
> {       
>         int n = 5;
>         int (*q2)[n] = q;
>         (*q2)[0] = 2;
> }
> 
> One could argue that there is a weaker requirement for having an object of 
> type
> int[n] present than for struct { int x[n]; } because we do not access the 
> array
> directly but it decays to a pointer. (but then, other languages have array
> assignment, so why does the middle-end care about this C peculiarity?) 

So in theory we could disregard the VLA-sized components for TBAA
which would make the access behaved as if it were a int * indirect access.
I think if you write it as array as above that's already what happens.

Note that even without LTO when you enable inlining you'd expose two
different structures with two different alias-sets, possibly leading
to wrong-code (look at the RTL expansion dump and check alias-sets).

As said, for arrays it probably works as-is since these gets the alias
set of the component.

> There is also no indication in documentation that structs with variable size
> follow different rules than conventional structs.   So my preference would be
> to fix this somehow.  Otherwise we should document this as a limitation.

Local declared structs in principle follow the same logic (but they
get promoted "global" due to implementation details I think).

Reply via email to