Unified · Split
| @@ -207,16 +207,17 @@ void load(int r, SValue *sv) · 206 unmodified lines | ||
| 207 | 207 | } else if ((ft & VT_BTYPE) == VT_LDOUBLE) { |
| 208 | 208 | o(0xdb); /* fldt */ |
| 209 | 209 | r = 5; |
| 210 | − } else if ((ft & VT_TYPE) == VT_BYTE) | |
| 210 | + } else if ((ft & VT_TYPE) == VT_BYTE) { | |
| 211 | 211 | o(0xbe0f); /* movsbl */ |
| 212 | − else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) | |
| 212 | + } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) { | |
| 213 | 213 | o(0xb60f); /* movzbl */ |
| 214 | − else if ((ft & VT_TYPE) == VT_SHORT) | |
| 214 | + } else if ((ft & VT_TYPE) == VT_SHORT) { | |
| 215 | 215 | o(0xbf0f); /* movswl */ |
| 216 | − else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) | |
| 216 | + } else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) { | |
| 217 | 217 | o(0xb70f); /* movzwl */ |
| 218 | − else | |
| 218 | + } else { | |
| 219 | 219 | o(0x8b); /* movl */ |
| 220 | + } | |
| 220 | 221 | gen_modrm(r, fr, fc); |
| 221 | 222 | } else { |
| 222 | 223 | if (v == VT_CONST) { |
| @@ -303,7 +304,7 @@ void gfunc_param(GFuncContext *c) · 80 unmodified lines | ||
| 303 | 304 | r = get_reg(RC_INT); |
| 304 | 305 | o(0x89); /* mov %esp, r */ |
| 305 | 306 | o(0xe0 + r); |
| 306 | − vset(VT_INT, r, 0); | |
| 307 | + vset(vtop->t, r | VT_LVAL, 0); | |
| 307 | 308 | vswap(); |
| 308 | 309 | vstore(); |
| 309 | 310 | c->args_size += size; |
| @@ -655,11 +656,22 @@ void gen_opf(int op) · 345 unmodified lines | ||
| 655 | 656 | gv(RC_FLOAT); |
| 656 | 657 | vswap(); |
| 657 | 658 | } |
| 659 | + swapped = 0; | |
| 660 | + /* swap the stack if needed so that t1 is the register and t2 is | |
| 661 | + the memory reference */ | |
| 662 | + if (vtop[-1].r & VT_LVAL) { | |
| 663 | + vswap(); | |
| 664 | + swapped = 1; | |
| 665 | + } | |
| 658 | 666 | if (op >= TOK_ULT && op <= TOK_GT) { |
| 659 | 667 | /* load on stack second operand */ |
| 660 | 668 | load(REG_ST0, vtop); |
| 661 | 669 | save_reg(REG_EAX); /* eax is used by FP comparison code */ |
| 662 | 670 | if (op == TOK_GE || op == TOK_GT) |
| 671 | + swapped = !swapped; | |
| 672 | + else if (op == TOK_EQ || op == TOK_NE) | |
| 673 | + swapped = 0; | |
| 674 | + if (swapped) | |
| 663 | 675 | o(0xc9d9); /* fxch %st(1) */ |
| 664 | 676 | o(0xe9da); /* fucompp */ |
| 665 | 677 | o(0xe0df); /* fnstsw %ax */ |
| @@ -681,13 +693,6 @@ void gen_opf(int op) · 15 unmodified lines | ||
| 681 | 693 | vtop->r = VT_CMP; |
| 682 | 694 | vtop->c.i = op; |
| 683 | 695 | } else { |
| 684 | − swapped = 0; | |
| 685 | − /* swap the stack if needed so that t1 is the register and t2 is | |
| 686 | − the memory reference */ | |
| 687 | − if (vtop[-1].r & VT_LVAL) { | |
| 688 | − vswap(); | |
| 689 | − swapped = 1; | |
| 690 | − } | |
| 691 | 696 | /* no memory reference possible for long double operations */ |
| 692 | 697 | if ((vtop->t & VT_BTYPE) == VT_LDOUBLE) { |
| 693 | 698 | load(REG_ST0, vtop); |
| @@ -821,45 +826,57 @@ void gen_cvt_ftof(int t) · 127 unmodified lines | ||
| 821 | 826 | |
| 822 | 827 | /* bound check support functions */ |
| 823 | 828 | #ifdef CONFIG_TCC_BCHECK |
| 824 | −/* generate first part of bounded pointer addition */ | |
| 825 | −void gen_bounded_ptr_add1(void) | |
| 829 | + | |
| 830 | +/* generate a bounded pointer addition */ | |
| 831 | +void gen_bounded_ptr_add(void) | |
| 826 | 832 | { |
| 833 | + int addr; | |
| 827 | 834 | /* prepare fast i386 function call (args in eax and edx) */ |
| 828 | 835 | gv2(RC_EAX, RC_EDX); |
| 829 | 836 | /* save all temporary registers */ |
| 830 | − vtop--; | |
| 831 | − vtop->r = VT_CONST; | |
| 832 | − save_regs(0); | |
| 837 | + vtop -= 2; | |
| 838 | + save_regs(0); | |
| 839 | + /* do a fast function call */ | |
| 840 | + addr = ind; | |
| 841 | + oad(0xe8, (int)__bound_ptr_add - ind - 5); | |
| 842 | + /* returned pointer is in eax */ | |
| 843 | + vtop++; | |
| 844 | + vtop->r = REG_EAX | VT_BOUNDED; | |
| 845 | + vtop->c.ul = addr; /* address of bounding function call point */ | |
| 833 | 846 | } |
| 834 | 847 | |
| 835 | −/* if deref is true, then also test dereferencing */ | |
| 836 | −void gen_bounded_ptr_add2(int deref) | |
| 848 | +/* patch pointer addition in vtop so that pointer dereferencing is | |
| 849 | + also tested */ | |
| 850 | +void gen_bounded_ptr_deref(void) | |
| 837 | 851 | { |
| 838 | 852 | void *func; |
| 839 | − int size, align; | |
| 840 | − | |
| 841 | − if (deref) { | |
| 853 | + int size, align, addr; | |
| 854 | + | |
| 855 | + size = 0; | |
| 856 | + /* XXX: put that code in generic part of tcc */ | |
| 857 | + if (!is_float(vtop->t)) { | |
| 858 | + if (vtop->r & VT_LVAL_BYTE) | |
| 859 | + size = 1; | |
| 860 | + else if (vtop->r & VT_LVAL_SHORT) | |
| 861 | + size = 2; | |
| 862 | + } | |
| 863 | + if (!size) | |
| 842 | 864 | size = type_size(vtop->t, &align); |
| 843 | − switch(size) { | |
| 844 | − case 1: func = __bound_ptr_indir1; break; | |
| 845 | − case 2: func = __bound_ptr_indir2; break; | |
| 846 | − case 4: func = __bound_ptr_indir4; break; | |
| 847 | − case 8: func = __bound_ptr_indir8; break; | |
| 848 | − case 12: func = __bound_ptr_indir12; break; | |
| 849 | − case 16: func = __bound_ptr_indir16; break; | |
| 850 | − default: | |
| 851 | − error("unhandled size when derefencing bounded pointer"); | |
| 852 | − func = NULL; | |
| 853 | − break; | |
| 854 | − } | |
| 855 | − } else { | |
| 856 | − func = __bound_ptr_add; | |
| 865 | + switch(size) { | |
| 866 | + case 1: func = __bound_ptr_indir1; break; | |
| 867 | + case 2: func = __bound_ptr_indir2; break; | |
| 868 | + case 4: func = __bound_ptr_indir4; break; | |
| 869 | + case 8: func = __bound_ptr_indir8; break; | |
| 870 | + case 12: func = __bound_ptr_indir12; break; | |
| 871 | + case 16: func = __bound_ptr_indir16; break; | |
| 872 | + default: | |
| 873 | + error("unhandled size when derefencing bounded pointer"); | |
| 874 | + func = NULL; | |
| 875 | + break; | |
| 857 | 876 | } |
| 858 | 877 | |
| 859 | − /* do a fast function call */ | |
| 860 | − oad(0xe8, (int)func - ind - 5); | |
| 861 | − /* return pointer is there */ | |
| 862 | − vtop->r = REG_EAX; | |
| 878 | + addr = vtop->c.ul; | |
| 879 | + *(int *)(addr + 1) = (int)func - addr - 5; | |
| 863 | 880 | } |
| 864 | 881 | #endif |
| 865 | 882 | |