From a66ba1f2a113c1f8b775c5c0a77061298fe5168e Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Thu, 12 May 2016 01:12:04 +0200 Subject: [PATCH] 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; --- tccgen.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tccgen.c b/tccgen.c index 7842309..55befb1 100644 --- a/tccgen.c +++ b/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;