From 812781cd1130059f4ac74608fbd6b8f1cff1d8b1 Mon Sep 17 00:00:00 2001 From: Joe Soroka Date: Mon, 11 Apr 2011 23:39:27 -0700 Subject: [PATCH] simplify/rollback VLA pointer subtraction I don't know if it makes a difference to gen_op(TOK_PDIV) or not, but logically the ptr1_is_vla test in TP's VLA patch seems out of order, where the patch to fix it would be: ------------------------------------------------------------------ @@ -1581,15 +1581,15 @@ ST_FUNC void gen_op(int op) u = pointed_size(&vtop[-1].type); } gen_opic(op); + if (ptr1_is_vla) + vswap(); /* set to integer type */ #ifdef TCC_TARGET_X86_64 vtop->type.t = VT_LLONG; #else vtop->type.t = VT_INT; #endif - if (ptr1_is_vla) - vswap(); - else + if (!ptr1_is_vla) vpushi(u); gen_op(TOK_PDIV); } else { ------------------------------------------------------------------ Instead of that patch, which increases the complexity of the code, this one fixes the problem by just rolling back and retrying with a simpler approach. --- tccgen.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tccgen.c b/tccgen.c index a1137c3a..beb88af1 100644 --- a/tccgen.c +++ b/tccgen.c @@ -1566,20 +1566,16 @@ ST_FUNC void gen_op(int op) } /* if both pointers, then it must be the '-' op */ if (bt1 == VT_PTR && bt2 == VT_PTR) { - int ptr1_is_vla; - - ptr1_is_vla = 0; if (op != '-') error("cannot use pointers here"); check_comparison_pointer_types(vtop - 1, vtop, op); /* XXX: check that types are compatible */ if (vtop[-1].type.t & VT_VLA) { vla_runtime_pointed_size(&vtop[-1].type); - vrott(3); - ptr1_is_vla = 1; } else { - u = pointed_size(&vtop[-1].type); + vpushi(pointed_size(&vtop[-1].type)); } + vrott(3); gen_opic(op); /* set to integer type */ #ifdef TCC_TARGET_X86_64 @@ -1587,10 +1583,7 @@ ST_FUNC void gen_op(int op) #else vtop->type.t = VT_INT; #endif - if (ptr1_is_vla) - vswap(); - else - vpushi(u); + vswap(); gen_op(TOK_PDIV); } else { /* exactly one pointer : must be '+' or '-'. */ -- 2.11.4.GIT