Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-06 Thread Qing Zhao
On Aug 5, 2024, at 16:59, Alejandro Colomar wrote: The “counted-by” attribute currently is not in the TYPE system, and we plan to add it into the TYPE system later through language standard (or an GCC extension). If that happens, then both the “sizeof” and the “__lengthof__” operators should

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Alejandro Colomar
Hi Qing, On Mon, Aug 05, 2024 at 10:41:43PM GMT, Martin Uecker wrote: > Am Montag, dem 05.08.2024 um 20:10 + schrieb Qing Zhao: > > On Aug 5, 2024, at 06:33, Martin Uecker wrote: > > > > > > Am Montag, dem 05.08.2024 um 11:50 +0200 schrieb Jakub Jelinek: > > > > On Mon, Aug 05, 2024 at 11:45

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Martin Uecker
Am Montag, dem 05.08.2024 um 20:10 + schrieb Qing Zhao: > On Aug 5, 2024, at 06:33, Martin Uecker wrote: > > > > Am Montag, dem 05.08.2024 um 11:50 +0200 schrieb Jakub Jelinek: > > > On Mon, Aug 05, 2024 at 11:45:56AM +0200, Alejandro Colomar wrote: > > > > [CC += Kees, Qing] > > > > > > > >

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Qing Zhao
On Aug 5, 2024, at 06:33, Martin Uecker wrote: > > Am Montag, dem 05.08.2024 um 11:50 +0200 schrieb Jakub Jelinek: >> On Mon, Aug 05, 2024 at 11:45:56AM +0200, Alejandro Colomar wrote: >>> [CC += Kees, Qing] >>> >>> Hi Joseph, >>> >>> On Sun, Aug 04, 2024 at 08:34:24PM GMT, Alejandro Colomar wr

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Alejandro Colomar
Hi Martin, On Mon, Aug 05, 2024 at 06:05:15PM GMT, Martin Uecker wrote: > > > > However, if I turn on -Wvla, both get a warning: > > > > len.c: At top level: > > len.c:288:1: warning: ISO C90 forbids variable length array ‘x’ [-Wvla] > > 288 | void foo(char (*a)[3][*], int (*x)[__l

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Martin Uecker
Am Montag, dem 05.08.2024 um 17:27 +0200 schrieb Alejandro Colomar: > Hi Martin, > ... > > But I think you might make it unnecessarily complicated. It > > should be sufficient to look at the outermost size. You > > can completely ignore thatever happens There > > should be three cases if I am n

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Alejandro Colomar
Hi Martin, On Mon, Aug 05, 2024 at 03:35:06PM GMT, Martin Uecker wrote: > > > > > > For incomplete arrays, basically we have the following different > > > > > > variants for arrays: > > > > > > > > > > > > T[ ] incomplete: !TYPE_DOMAIN > > > > > > T[1] constant size: TYPE_MAX_VALUE == INTEGER_CS

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Martin Uecker
Am Montag, dem 05.08.2024 um 13:59 +0200 schrieb Alejandro Colomar: > On Mon, Aug 05, 2024 at 01:58:18PM GMT, Alejandro Colomar wrote: > > On Mon, Aug 05, 2024 at 01:57:35PM GMT, Alejandro Colomar wrote: > > > On Mon, Aug 05, 2024 at 01:55:50PM GMT, Alejandro Colomar wrote: > > > > Hi Martin, > > >

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Alejandro Colomar
On Mon, Aug 05, 2024 at 01:58:18PM GMT, Alejandro Colomar wrote: > On Mon, Aug 05, 2024 at 01:57:35PM GMT, Alejandro Colomar wrote: > > On Mon, Aug 05, 2024 at 01:55:50PM GMT, Alejandro Colomar wrote: > > > Hi Martin, > > > > > > On Sun, Aug 04, 2024 at 11:39:26AM GMT, Martin Uecker wrote: > > > >

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Alejandro Colomar
On Mon, Aug 05, 2024 at 01:57:35PM GMT, Alejandro Colomar wrote: > On Mon, Aug 05, 2024 at 01:55:50PM GMT, Alejandro Colomar wrote: > > Hi Martin, > > > > On Sun, Aug 04, 2024 at 11:39:26AM GMT, Martin Uecker wrote: > > > > BTW, I still don't understand what `if (! TYPE_DOMAIN (type))` means, > >

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Alejandro Colomar
On Mon, Aug 05, 2024 at 01:55:50PM GMT, Alejandro Colomar wrote: > Hi Martin, > > On Sun, Aug 04, 2024 at 11:39:26AM GMT, Martin Uecker wrote: > > > BTW, I still don't understand what `if (! TYPE_DOMAIN (type))` means, > > > within array_type_nelts_minus_one(). What code triggers that condition?

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Alejandro Colomar
Hi Martin, On Sun, Aug 04, 2024 at 11:39:26AM GMT, Martin Uecker wrote: > > BTW, I still don't understand what `if (! TYPE_DOMAIN (type))` means, > > within array_type_nelts_minus_one(). What code triggers that condition? > > Am I missing error handling for that? Thanks! > > For incomplete arra

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Martin Uecker
Am Montag, dem 05.08.2024 um 11:50 +0200 schrieb Jakub Jelinek: > On Mon, Aug 05, 2024 at 11:45:56AM +0200, Alejandro Colomar wrote: > > [CC += Kees, Qing] > > > > Hi Joseph, > > > > On Sun, Aug 04, 2024 at 08:34:24PM GMT, Alejandro Colomar wrote: > > > On Sun, Aug 04, 2024 at 08:02:25PM GMT, Mar

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Jakub Jelinek
On Mon, Aug 05, 2024 at 11:45:56AM +0200, Alejandro Colomar wrote: > [CC += Kees, Qing] > > Hi Joseph, > > On Sun, Aug 04, 2024 at 08:34:24PM GMT, Alejandro Colomar wrote: > > On Sun, Aug 04, 2024 at 08:02:25PM GMT, Martin Uecker wrote: > > D'oh! I screwed it. I wanted to have written this: > >

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-05 Thread Alejandro Colomar
[CC += Kees, Qing] Hi Joseph, On Sun, Aug 04, 2024 at 08:34:24PM GMT, Alejandro Colomar wrote: > On Sun, Aug 04, 2024 at 08:02:25PM GMT, Martin Uecker wrote: > D'oh! I screwed it. I wanted to have written this: > > $ cat star.c > void foo(char (*a)[3][*], int (*x)[__lengthof__(*a)

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-04 Thread Martin Uecker
Am Sonntag, dem 04.08.2024 um 20:34 +0200 schrieb Alejandro Colomar: > On Sun, Aug 04, 2024 at 08:02:25PM GMT, Martin Uecker wrote: > > Hi Alex, > > Hi Martin, > > > > Is this missing diagnostics? > > > > > > $ cat star.c > > > void foo(char (*a)[3][*], int (*x)[__lengthof__(*a)]); > > >

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-04 Thread Alejandro Colomar
On Sun, Aug 04, 2024 at 08:02:25PM GMT, Martin Uecker wrote: > Hi Alex, Hi Martin, > > Is this missing diagnostics? > > > > $ cat star.c > > void foo(char (*a)[3][*], int (*x)[__lengthof__(*a)]); > > void bar(char (*a)[*][3], int (*x)[__lengthof__(*a)]); > > void foos(char (*a)[

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-04 Thread Martin Uecker
Hi Alex, Am Sonntag, dem 04.08.2024 um 19:49 +0200 schrieb Alejandro Colomar: > Hi Martin, > > On Sun, Aug 04, 2024 at 06:43:46PM GMT, Alejandro Colomar wrote: > > On Sun, Aug 04, 2024 at 06:40:14PM GMT, Alejandro Colomar wrote: > > > > The last  > > > > case should return a non-constant. > > >

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-04 Thread Alejandro Colomar
Hi Martin, On Sun, Aug 04, 2024 at 06:43:46PM GMT, Alejandro Colomar wrote: > On Sun, Aug 04, 2024 at 06:40:14PM GMT, Alejandro Colomar wrote: > > > The last  > > > case should return a non-constant. > > > > The last case [*] is only allowed in prototypes. How should we get the > > non-constant

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-04 Thread Martin Uecker
Hi Alex, Am Sonntag, dem 04.08.2024 um 18:40 +0200 schrieb Alejandro Colomar: > Hi Martin, > > On Sun, Aug 04, 2024 at 11:39:26AM GMT, Martin Uecker wrote: > > Am Sonntag, dem 04.08.2024 um 10:25 +0200 schrieb Alejandro Colomar: > > > Hi Martin, > > > > > > On Sun, Aug 04, 2024 at 07:38:49AM G

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-04 Thread Alejandro Colomar
On Sun, Aug 04, 2024 at 06:40:14PM GMT, Alejandro Colomar wrote: > > The last  > > case should return a non-constant. > > The last case [*] is only allowed in prototypes. How should we get the > non-constant value? It's just another way to say [], isn't it? > > > If you reuse the sizeof code, i

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-04 Thread Alejandro Colomar
Hi Martin, On Sun, Aug 04, 2024 at 11:39:26AM GMT, Martin Uecker wrote: > Am Sonntag, dem 04.08.2024 um 10:25 +0200 schrieb Alejandro Colomar: > > Hi Martin, > > > > On Sun, Aug 04, 2024 at 07:38:49AM GMT, Martin Uecker wrote: > > > Am Sonntag, dem 04.08.2024 um 01:17 +0200 schrieb Alejandro Colo

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-04 Thread Martin Uecker
Am Sonntag, dem 04.08.2024 um 10:25 +0200 schrieb Alejandro Colomar: > Hi Martin, > > On Sun, Aug 04, 2024 at 07:38:49AM GMT, Martin Uecker wrote: > > Am Sonntag, dem 04.08.2024 um 01:17 +0200 schrieb Alejandro Colomar: > > > > > > FUTURE DIRECTIONS: > > > > > > We could make it work with arra

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-04 Thread Alejandro Colomar
Hi Martin, On Sun, Aug 04, 2024 at 07:38:49AM GMT, Martin Uecker wrote: > Am Sonntag, dem 04.08.2024 um 01:17 +0200 schrieb Alejandro Colomar: > > > > FUTURE DIRECTIONS: > > > > We could make it work with array parameters to functions, and > > somehow magically return the length designat

Re: [RFC v3 3/3] c: Add __lengthof__() operator

2024-08-03 Thread Martin Uecker
Am Sonntag, dem 04.08.2024 um 01:17 +0200 schrieb Alejandro Colomar: > > FUTURE DIRECTIONS: > > We could make it work with array parameters to functions, and > somehow magically return the length designator of the array, > regardless of it being really a pointer. And maybe fl

[RFC v3 3/3] c: Add __lengthof__() operator

2024-08-03 Thread Alejandro Colomar
This operator is similar to sizeof() but can only be applied to an array, and returns its length (number of elements). TO BE DECIDED BEFORE MERGING: It would be better to not evaluate the operand if the top-level array is not a VLA. FUTURE DIRECTIONS: We could make it wo