| @@ -683,7 +683,7 @@ static void move_reg(int r, int s, int t) · 682 unmodified lines |
| 683 | 683 | /* get address of vtop (vtop MUST BE an lvalue) */ |
| 684 | 684 | ST_FUNC void gaddrof(void) |
| 685 | 685 | { |
| 686 | | − if (vtop->r & VT_REF) |
| 686 | + if (vtop->r & VT_REF && !nocode_wanted) |
| 687 | 687 | gv(RC_INT); |
| 688 | 688 | vtop->r &= ~VT_LVAL; |
| 689 | 689 | /* tricky: if saved lvalue, then we can go back to lvalue */ |
| @@ -1848,7 +1848,7 @@ ST_FUNC void gen_op(int op) · 1158 unmodified lines |
| 1848 | 1848 | } |
| 1849 | 1849 | } |
| 1850 | 1850 | // Make sure that we have converted to an rvalue: |
| 1851 | | − if (vtop->r & VT_LVAL) |
| 1851 | + if (vtop->r & VT_LVAL && !nocode_wanted) |
| 1852 | 1852 | gv(is_float(vtop->type.t & VT_BTYPE) ? RC_FLOAT : RC_INT); |
| 1853 | 1853 | } |
| 1854 | 1854 | |
| @@ -1951,7 +1951,7 @@ static void gen_cast(CType *type) · 96 unmodified lines |
| 1951 | 1951 | } |
| 1952 | 1952 | |
| 1953 | 1953 | /* bitfields first get cast to ints */ |
| 1954 | | − if (vtop->type.t & VT_BITFIELD) { |
| 1954 | + if (vtop->type.t & VT_BITFIELD && !nocode_wanted) { |
| 1955 | 1955 | gv(RC_INT); |
| 1956 | 1956 | } |
| 1957 | 1957 | |
| @@ -2057,7 +2057,7 @@ static void gen_cast(CType *type) · 99 unmodified lines |
| 2057 | 2057 | } |
| 2058 | 2058 | #if !defined(TCC_TARGET_ARM64) && !defined(TCC_TARGET_X86_64) |
| 2059 | 2059 | } else if ((dbt & VT_BTYPE) == VT_LLONG) { |
| 2060 | | − if ((sbt & VT_BTYPE) != VT_LLONG) { |
| 2060 | + if ((sbt & VT_BTYPE) != VT_LLONG && !nocode_wanted) { |
| 2061 | 2061 | /* scalar to long long */ |
| 2062 | 2062 | /* machine independent conversion */ |
| 2063 | 2063 | gv(RC_INT); |
| @@ -2085,7 +2085,7 @@ static void gen_cast(CType *type) · 21 unmodified lines |
| 2085 | 2085 | (dbt & VT_BTYPE) == VT_FUNC) { |
| 2086 | 2086 | if ((sbt & VT_BTYPE) != VT_LLONG && |
| 2087 | 2087 | (sbt & VT_BTYPE) != VT_PTR && |
| 2088 | | − (sbt & VT_BTYPE) != VT_FUNC) { |
| 2088 | + (sbt & VT_BTYPE) != VT_FUNC && !nocode_wanted) { |
| 2089 | 2089 | /* need to convert from 32bit to 64bit */ |
| 2090 | 2090 | gv(RC_INT); |
| 2091 | 2091 | if (sbt != (VT_INT | VT_UNSIGNED)) { |
| @@ -2115,7 +2115,7 @@ static void gen_cast(CType *type) · 23 unmodified lines |
| 2115 | 2115 | force_charshort_cast(dbt); |
| 2116 | 2116 | } else if ((dbt & VT_BTYPE) == VT_INT) { |
| 2117 | 2117 | /* scalar to int */ |
| 2118 | | − if (sbt == VT_LLONG) { |
| 2118 | + if (sbt == VT_LLONG && !nocode_wanted) { |
| 2119 | 2119 | /* from long long: just take low order word */ |
| 2120 | 2120 | lexpand(); |
| 2121 | 2121 | vpop(); |
| @@ -2614,15 +2614,15 @@ ST_FUNC void vstore(void) · 492 unmodified lines |
| 2614 | 2614 | vpop(); |
| 2615 | 2615 | |
| 2616 | 2616 | } else { |
| 2617 | + if (!nocode_wanted) { |
| 2617 | 2618 | #ifdef CONFIG_TCC_BCHECK |
| 2618 | | − /* bound check case */ |
| 2619 | | − if (vtop[-1].r & VT_MUSTBOUND) { |
| 2620 | | − vswap(); |
| 2621 | | − gbound(); |
| 2622 | | − vswap(); |
| 2623 | | − } |
| 2619 | + /* bound check case */ |
| 2620 | + if (vtop[-1].r & VT_MUSTBOUND) { |
| 2621 | + vswap(); |
| 2622 | + gbound(); |
| 2623 | + vswap(); |
| 2624 | + } |
| 2624 | 2625 | #endif |
| 2625 | | − if (!nocode_wanted) { |
| 2626 | 2626 | rc = RC_INT; |
| 2627 | 2627 | if (is_float(ft)) { |
| 2628 | 2628 | rc = RC_FLOAT; |
| @@ -2686,7 +2686,10 @@ ST_FUNC void inc(int post, int c) · 57 unmodified lines |
| 2686 | 2686 | test_lvalue(); |
| 2687 | 2687 | vdup(); /* save lvalue */ |
| 2688 | 2688 | if (post) { |
| 2689 | | − gv_dup(); /* duplicate value */ |
| 2689 | + if (!nocode_wanted) |
| 2690 | + gv_dup(); /* duplicate value */ |
| 2691 | + else |
| 2692 | + vdup(); /* duplicate value */ |
| 2690 | 2693 | vrotb(3); |
| 2691 | 2694 | vrotb(3); |
| 2692 | 2695 | } |
| @@ -3773,6 +3776,8 @@ ST_FUNC void unary(void) · 1080 unmodified lines |
| 3773 | 3776 | gen_cast(&type); |
| 3774 | 3777 | } |
| 3775 | 3778 | } else if (tok == '{') { |
| 3779 | + if (nocode_wanted) |
| 3780 | + tcc_error("statement expression in global scope"); |
| 3776 | 3781 | /* save all registers */ |
| 3777 | 3782 | save_regs(0); |
| 3778 | 3783 | /* statement expression : we do not accept break/continue |
| @@ -3813,10 +3818,12 @@ ST_FUNC void unary(void) · 34 unmodified lines |
| 3813 | 3818 | vtop->c.i = !vtop->c.i; |
| 3814 | 3819 | } else if ((vtop->r & VT_VALMASK) == VT_CMP) |
| 3815 | 3820 | vtop->c.i = vtop->c.i ^ 1; |
| 3816 | | − else { |
| 3821 | + else if (!nocode_wanted) { |
| 3817 | 3822 | save_regs(1); |
| 3818 | 3823 | vseti(VT_JMP, gvtst(1, 0)); |
| 3819 | 3824 | } |
| 3825 | + else |
| 3826 | + vtop--; |
| 3820 | 3827 | break; |
| 3821 | 3828 | case '~': |
| 3822 | 3829 | next(); |
| @@ -3954,6 +3961,8 @@ ST_FUNC void unary(void) · 131 unmodified lines |
| 3954 | 3961 | |
| 3955 | 3962 | #ifdef TCC_TARGET_ARM64 |
| 3956 | 3963 | case TOK___va_start: { |
| 3964 | + if (!nocode_wanted) |
| 3965 | + tcc_error("statement in global scope"); |
| 3957 | 3966 | next(); |
| 3958 | 3967 | skip('('); |
| 3959 | 3968 | expr_eq(); |
| @@ -3967,6 +3976,8 @@ ST_FUNC void unary(void) · 7 unmodified lines |
| 3967 | 3976 | break; |
| 3968 | 3977 | } |
| 3969 | 3978 | case TOK___va_arg: { |
| 3979 | + if (!nocode_wanted) |
| 3980 | + tcc_error("statement in global scope"); |
| 3970 | 3981 | CType type; |
| 3971 | 3982 | next(); |
| 3972 | 3983 | skip('('); |
| @@ -3992,7 +4003,7 @@ ST_FUNC void unary(void) · 19 unmodified lines |
| 3992 | 4003 | break; |
| 3993 | 4004 | } |
| 3994 | 4005 | #endif |
| 3995 | | − |
| 4006 | + /* pre operations */ |
| 3996 | 4007 | case TOK_INC: |
| 3997 | 4008 | case TOK_DEC: |
| 3998 | 4009 | t = tok; |