aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Matz <matz@suse.de>2016-05-12 01:12:04 +0200
committerMichael Matz <matz@suse.de>2016-05-12 01:12:04 +0200
commita66ba1f2a113c1f8b775c5c0a77061298fe5168e (patch)
tree20844942e1521aad002ef6bf1ce814ce2da835b6
parent6bd8c936e33db20f7023e11228bc2f2a4fb51f2e (diff)
downloadtinycc-a66ba1f2a113c1f8b775c5c0a77061298fe5168e.tar.gz
tinycc-a66ba1f2a113c1f8b775c5c0a77061298fe5168e.tar.bz2
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;
-rw-r--r--tccgen.c6
1 files 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;