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

--- Comment #36 from Martin Uecker <muecker at gwdg dot de> ---
Am Montag, dem 03.04.2023 um 20:29 +0000 schrieb qinzhao at gcc dot gnu.org:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896
> 
> --- Comment #35 from qinzhao at gcc dot gnu.org ---
> (In reply to Martin Uecker from comment #34)
> > Created attachment 54787 [details]
> > patch for C FE to add size expressions to VM types in structs
> 
> thanks a lot for the patch.
> 
> could you please provide a small testing case that works with this patch that 
> I
> can take a further look?

I considered pointers to arrays:

struct P {
  int n;
  char (*buf)[.n];
};

the FAM case needs more work and I guess there are
still many other problems with the patch.

> I tried very simple one, didn't compile:
> 
> struct P {
>   int k;
>   int x[.k];
> };
> 
> void
> foo (int n)
> {
>   struct P p;
>   p.k = n;
>   return;
> }
> 
> > 
> > It works with UBSan, but it isn't clear how this could pass the
> > information to the object size pass. This also does not work for
> > parameters: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109334
> 
> From your change, I can see that you put the ".k" info to the index of the
> array type for x[.k], so I guess that other passes can refer the index of the
> array type to get the max size of this array.
> 

The comments in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104970

imply that the size information does not survive long enough

> > 
> > So it seems for an attribute it might make sense to implement
> > it differently.
> implement should be different. but the functionality of the user interface is
> better to be kept consistent between attribute and language extension. i.e
> 
> in addition to the basic:
> 
> struct P {
>   int k;
>   int x[.k];
> };
> 
> will you support expressions:
> 
> struct P {
>   int k;
>   int x[.k * 4];
> }
> ?
> or other more complicated syntax?

I am not sure.  I am still experimenting with this to gain experience.

It is easy to move the parser code elsehwere and then
complicated expressions can be used.

But the size expression is evaluated each time when the member is
accessed.  Do we really want to run arbitrary code at this point? 
Maybe the size expressions should be limited to very simple
expressions without side effects.

Martin

>

Reply via email to