[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Pointers to variable-length arrays are broken
From: |
Ivan Kozlov |
Subject: |
Re: [Tinycc-devel] Pointers to variable-length arrays are broken |
Date: |
Fri, 03 Sep 2021 23:08:08 +0300 |
The issue appears to be that TCC creates a temporary object to store the computed address of the variable-length array. The _expression_ &a is then wrongly interpreted as taking the address of the temporary object, and not the array.
Attached is a workaround for x86-64 targets. I don’t understand the code, so I wouldn’t know how to fix this properly.
03.09.2021, 13:09, "Ivan Kozlov" <kanichos@yandex.ru>:
The following program miscompiles as of TCC 0.9.27:
#include <stdio.h>
int
main (void)
{
size_t n = 10;
int a[n];
printf ("%p\n%p\n", (void *)a, (void *)*&a);
}
The second address is off. GCC 10.2.0, among others, handles this correctly.
Pointers to constant-length arrays work as intended (and indeed have the same representation as the address of the first element of the target array).
vla-address-of.patch
Description: Text Data