[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Fwd: TCC VLA bug?

From: grischka
Subject: Re: [Tinycc-devel] Fwd: TCC VLA bug?
Date: Tue, 07 Dec 2021 20:52:00 +0100
User-agent: Thunderbird (Windows/20090812)

Michael Matz wrote:
So, the problematic type was:

  int (*)[a][b]

That's pointer to an vla-array of an vla-array of int.  All three (inner
array, outer array and pointer, but not the int) should be marked


IMO one (very) invariant convention is that VT_ARRAY rsp. VT_VLA
always also have VT_PTR.

Therefor if the outer pointer would have VT_VLA as you say above,
then it would be not a pointer to a VLA, but it would be a VLA,
as in

    int arr[z][a][b];

Anyway, now that I already did look into it (which initially I was
trying to avoid ;) I would maybe just replace all this:

            if (type1.ref->type.t & VT_VLA)
            else {
                u = pointed_size(&type1);
                if (u < 0)
                    tcc_error("unknown array element size");
       #if PTR_SIZE == 8
                /* XXX: cast to int ? (long long case) */

by that single line:

            vla_runtime_type_size(pointed_type(&vtop[-1].type), &align):

which looks as it would do the right thing automatically also for the
normal array (non-vla) case (but except the "unknown array size" check).

Of course one could rename "vla_runtime_type_size" to something better, then.

Btw, now that I already did look into it (which initially ... ;) I think
I found 2 related problems as can be seen with this (added to the original
test case):

    // int (*arr)[h][w];
    printf("diff = %d, size = %d/%d\n",
        arr + 1 - arr, sizeof *arr, sizeof (*arr + 1));

-- gr

In TCC we collapse the outer array+pointer into one type (a
pointer that also has VT_ARRAY/VT_VLA set), so there actually should be
two levels: the inner level a VT_VLA pointing to the VT_INT (with its
VLA runtime length being evaluated to sizeof(int) * b) and the outer
level a VT_VLA pointing to the inner VT_VLA (and its VLA runtime length
being evaluated to inner length * a).

I'm surprised that your patch didn't cause other problems, it seems
either the testsuite isn't testing VLAs very much, or that the VT_VLA
flag is set on types where it shouldn't have been (e.g. on the VT_INT
type that is in the type->ref of the 'int [n]' array type).



Tinycc-devel mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]