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" <[email protected]>:
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).
diff --git a/x86_64-gen.c b/x86_64-gen.c
index e33a38a..80a4822 100644
--- a/x86_64-gen.c
+++ b/x86_64-gen.c
@@ -474,7 +474,10 @@ void load(int r, SValue *sv)
gen_le32(fc);
}
} else if (v == VT_LOCAL) {
- orex(1,0,r,0x8d); /* lea xxx(%ebp), r */
+ if (sv->sym->type.t & VT_VLA)
+ orex(1,0,r,0x8b); /* mov xxx(%ebp), r */
+ else
+ orex(1,0,r,0x8d); /* lea xxx(%ebp), r */
gen_modrm(r, VT_LOCAL, sv->sym, fc);
} else if (v == VT_CMP) {
orex(0,r,0,0);
_______________________________________________ Tinycc-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/tinycc-devel
