mirror of
https://github.com/mirror/tinycc.git
synced 2025-03-24 10:00:07 +08:00
Error out on operations on structs
The check for structs was too late and on amd64 and aarch64 could lead to accepting and then asserting with code like: struct S {...} s; char *c = (char*)0x10 - s;
This commit is contained in:
parent
6bd8c936e3
commit
a66ba1f2a1
6
tccgen.c
6
tccgen.c
@ -1699,7 +1699,9 @@ ST_FUNC void gen_op(int op)
|
||||
bt1 = t1 & VT_BTYPE;
|
||||
bt2 = t2 & VT_BTYPE;
|
||||
|
||||
if (bt1 == VT_PTR || bt2 == VT_PTR) {
|
||||
if (bt1 == VT_STRUCT || bt2 == VT_STRUCT) {
|
||||
tcc_error("operation on a struct");
|
||||
} else if (bt1 == VT_PTR || bt2 == VT_PTR) {
|
||||
/* at least one operand is a pointer */
|
||||
/* relationnal op: must be both pointers */
|
||||
if (op >= TOK_ULT && op <= TOK_LOR) {
|
||||
@ -1820,8 +1822,6 @@ ST_FUNC void gen_op(int op)
|
||||
(t2 & (VT_BTYPE | VT_UNSIGNED)) == (VT_LLONG | VT_UNSIGNED))
|
||||
t |= VT_UNSIGNED;
|
||||
goto std_op;
|
||||
} else if (bt1 == VT_STRUCT || bt2 == VT_STRUCT) {
|
||||
tcc_error("comparison of struct");
|
||||
} else {
|
||||
/* integer operations */
|
||||
t = VT_INT;
|
||||
|
Loading…
Reference in New Issue
Block a user