Hi Martin,

On Sun, Jul 28, 2024 at 04:42:26PM GMT, Martin Uecker wrote:
> Am Sonntag, dem 28.07.2024 um 16:15 +0200 schrieb Alejandro Colomar:
> 
> ...
> > 
> > Does anyone know if we have the information available for getting that
> > value from the 'tree' object?  Or do we need some refactor first in
> > order to keep that information?
> 
> What I wanted to try is to not immediately adjust the type to a
> pointer and keep it represented as an array, so that the size is
> preserved.  We currently already have a flag that tells us that
> the type came from a parameter declared as an array, so we would
> do it the other way round and have a flag that tells us that it
> is really a pointer.  

Thanks!  Thanks makes sense.  I suspected you had something in mind.  :)

Do you remember that flag's name?  I can have a look at inverting that.

> In most cases the array would then decay and nothing needs to be
> changed, but in some cases we would special case it to get the 
> correct result (addressof / sizeof / typeof and maybe others).  
> Those are also cases which should have a warning anyway. So this
> *should* be simple, but I haven't tried.
> 
> I will look at you code later, but I would recommend to avoid
> refactoring that touches different parts of the compiler at this
> point.

I had to do patch 1/2 for having the function that gives me the nelts
value; other than that, I've tried to keep it minimal.

> I also wonder whether it would make sense to propose a GNU
> extension first instead of implementing a full prototype for
> the standard feature? I do not think we could merge the
> former without having an accepted proposal.

Do you mean a __lengthof__ operator first, without using the _L name
or <stdlength.h>?

If so, I agree.

> Martin

Cheers,
Alex

> > Alejandro Colomar (2):
> >   Merge definitions of array_type_nelts_top()
> >   c: Add _Lengthof() operator
> > 
> >  gcc/Makefile.in               |  1 +
> >  gcc/c-family/c-common.cc      | 20 +++++++++
> >  gcc/c-family/c-common.def     |  4 ++
> >  gcc/c-family/c-common.h       |  2 +
> >  gcc/c/c-parser.cc             | 35 +++++++++++----
> >  gcc/c/c-tree.h                |  4 ++
> >  gcc/c/c-typeck.cc             | 84 +++++++++++++++++++++++++++++++++++
> >  gcc/cp/cp-tree.h              |  1 -
> >  gcc/cp/operators.def          |  1 +
> >  gcc/cp/tree.cc                | 13 ------
> >  gcc/ginclude/stdlength.h      | 35 +++++++++++++++
> >  gcc/rust/backend/rust-tree.cc | 13 ------
> >  gcc/rust/backend/rust-tree.h  |  2 -
> >  gcc/target.h                  |  3 ++
> >  gcc/tree.cc                   | 13 ++++++
> >  gcc/tree.h                    |  1 +
> >  16 files changed, 195 insertions(+), 37 deletions(-)
> >  create mode 100644 gcc/ginclude/stdlength.h
> > 
> > Range-diff against v0:
> > -:  ----------- > 1:  507f5a51e17 Merge definitions of 
> > array_type_nelts_top()
> > -:  ----------- > 2:  e5835b982af c: Add _Lengthof() operator
> 

-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature

Reply via email to