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.  

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 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.

Martin

> 
> Also, I've reused much of sizeof's code, and maybe I should change some
> of that.  It's my first contribution to gcc of this size, and I don't
> yet know what some of those internals mean.  While my implementation
> seems to be working (for the test above), I guess it's not ideal in
> terms of readability, and may also not work well with C++ or some corner
> cases.  Can somebody with more experience have a look at the code?
> 
> I suspect this is not yet ready, and thus doesn't have a ChangeLog.
> 
> Have a lovely day!
> 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

Reply via email to