History

Add some missing nocode_wanted guard

int i = i++ causes a segfault because of missing guard. Looking recursively at all backend functions called from middle end several more guard appeared to be missing.

Thomas Preud'homme committed 11 years ago

Commit 5bcc3ee1 parent 68605ab4 files · +30 −16Browse files

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t