Am Donnerstag, dem 08.08.2024 um 00:09 +0200 schrieb Alejandro Colomar: > Hi Martin, > > ...
> > > > > > I would personally prefer supporting [0], and consider that not > > > supporting [*] is a bug in the implementation of [*] (and thus not my > > > problem). > > > > > > However, since GCC doesn't support 0-length arrays, I'm not sure that > > > would be correct. > > > > > > What do you think? > > > > I think the logic in your patch is OK as is. It does not exactly > > what you want, as it now treats some [0] as [*] but I would not > > make the logic more complex here when we will fix it properly > > anyway. > > I'm detecting some issues with my patches. > > $ cat zero.c > static int A[__lengthof__(int [0])]; > static int B[__lengthof__(A)]; > > static int C[0]; > static int D[__lengthof__(C)]; > > void fa(char (*a)[3][*], int (*x)[__lengthof__(*a)]); // x: array > void fb(char (*a)[*][3], int (*x)[__lengthof__(*a)]); // x: vla > void fc(char (*a)[3], int (*x)[__lengthof__(*a)]); // x: array > void fd(char (*a)[0], int (*x)[__lengthof__(*a)]); // x: ? > void fe(char (*a)[*], int (*x)[__lengthof__(*a)]); // x: vla > void ff(char (*a)[*], int (*x)[*]); // x: array > > > static int W[1]; > static int X[__lengthof__(W)]; > static int Y[0]; > static int Z[__lengthof__(Y)]; > > $ /opt/local/gnu/gcc/lengthof/bin/gcc zero.c > zero.c:18:12: error: variably modified ‘Z’ at file scope > 18 | static int Z[__lengthof__(Y)]; > | ^ > > > See that D, which is identical to Z, does not cause an error. > There's one case of [0] resulting in a constant expression, and another > in a VLA. Can you please help investigate why it's happening? This seems to be another bug where we incorrectly set C_TYPE_VARIABLE_SIZE and this also affects sizeof: https://godbolt.org/z/a8Ej6c5jr Strangely it seems related to the function declaration with the unspecified size before. I will look into this, I am just working on some checking functions that make sure that those bits are consistent all the time because I also missed some cases where I need to set C_TYPE_VARIABLY_MODIFIED I filed a new bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116284 ... > | ^ > > If I make [0] always result in a constant expression (and thus break > some [*] cases), by doing > > - var = var || (zero && C_TYPE_VARIABLE_SIZE (type)); > > Then the problem disappears. But I'm worried that it might be hiding > the problem instead of removing it, since I don't really understand why > it's happening. Do you know why? > > Anyway, I'll remove that line to support [0]. But it would be > interesting to learn why this problem triggers. You need the line to support variable size arrays. Please just uncomment your test with a reference to the bug for now and I will try fix this ASAP. Martin > Alex >