From 35475b5423db8c3949ea283cb79ab583f36bf04a Mon Sep 17 00:00:00 2001 From: grischka Date: Mon, 16 Dec 2019 18:48:31 +0100 Subject: [PATCH] remove VT_LVAL_BYTE etc. For some reason there was no point for that anymore. --- arm-gen.c | 2 +- arm64-gen.c | 8 ++--- c67-gen.c | 2 +- i386-gen.c | 13 ++------- riscv64-gen.c | 2 +- tcc.h | 6 ---- tccgen.c | 81 ++++++++++++--------------------------------------- x86_64-gen.c | 30 +++++++++---------- 8 files changed, 42 insertions(+), 102 deletions(-) diff --git a/arm-gen.c b/arm-gen.c index 92b2ee7d..a34d3cdb 100644 --- a/arm-gen.c +++ b/arm-gen.c @@ -1363,7 +1363,7 @@ from_stack: addr = (n + nf + sn) * 4; sn += size; } - sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | lvalue_type(type->t), + sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL, addr + 12); } last_itod_magic=0; diff --git a/arm64-gen.c b/arm64-gen.c index 26f6d610..760e70e0 100644 --- a/arm64-gen.c +++ b/arm64-gen.c @@ -446,7 +446,7 @@ static void arm64_load_cmp(int r, SValue *sv); ST_FUNC void load(int r, SValue *sv) { int svtt = sv->type.t; - int svr = sv->r & ~VT_LVAL_TYPE; + int svr = sv->r; int svrv = svr & VT_VALMASK; uint64_t svcul = (uint32_t)sv->c.i; svcul = svcul >> 31 & 1 ? svcul - ((uint64_t)1 << 32) : svcul; @@ -546,7 +546,7 @@ ST_FUNC void load(int r, SValue *sv) ST_FUNC void store(int r, SValue *sv) { int svtt = sv->type.t; - int svr = sv->r & ~VT_LVAL_TYPE; + int svr = sv->r; int svrv = svr & VT_VALMASK; uint64_t svcul = (uint32_t)sv->c.i; svcul = svcul >> 31 & 1 ? svcul - ((uint64_t)1 << 32) : svcul; @@ -1039,7 +1039,7 @@ ST_FUNC void gfunc_prolog(Sym *func_sym) a[i] < 32 ? 16 + (a[i] - 16) / 2 * 16 : 224 + ((a[i] - 32) >> 1 << 1)); sym_push(sym->v & ~SYM_FIELD, &sym->type, - (a[i] & 1 ? VT_LLOCAL : VT_LOCAL) | lvalue_type(sym->type.t), + (a[i] & 1 ? VT_LLOCAL : VT_LOCAL) | VT_LVAL, off); if (a[i] < 16) { @@ -1126,7 +1126,7 @@ ST_FUNC void gen_va_arg(CType *t) gaddrof(); r0 = intr(gv(RC_INT)); r1 = get_reg(RC_INT); - vtop[0].r = r1 | lvalue_type(t->t); + vtop[0].r = r1 | VT_LVAL; r1 = intr(r1); if (!hfa) { diff --git a/c67-gen.c b/c67-gen.c index d9b87d32..eccb01af 100644 --- a/c67-gen.c +++ b/c67-gen.c @@ -1964,7 +1964,7 @@ void gfunc_prolog(Sym *func_sym) /* define parameters */ while ((sym = sym->next) != NULL) { type = &sym->type; - sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | lvalue_type(type->t), addr); + sym_push(sym->v & ~SYM_FIELD, type, VT_LOCAL | VT_LVAL, addr); size = type_size(type, &align); size = (size + 3) & ~3; diff --git a/i386-gen.c b/i386-gen.c index 396df8b3..7fdc90cc 100644 --- a/i386-gen.c +++ b/i386-gen.c @@ -587,7 +587,7 @@ ST_FUNC void gfunc_prolog(Sym *func_sym) addr += size; } sym_push(sym->v & ~SYM_FIELD, type, - VT_LOCAL | lvalue_type(type->t), param_addr); + VT_LOCAL | VT_LVAL, param_addr); param_index++; } func_ret_sub = 0; @@ -1084,16 +1084,7 @@ ST_FUNC void gen_bounded_ptr_deref(void) if (nocode_wanted) return; - size = 0; - /* XXX: put that code in generic part of tcc */ - if (!is_float(vtop->type.t)) { - if (vtop->r & VT_LVAL_BYTE) - size = 1; - else if (vtop->r & VT_LVAL_SHORT) - size = 2; - } - if (!size) - size = type_size(&vtop->type, &align); + size = type_size(&vtop->type, &align); switch(size) { case 1: func = TOK___bound_ptr_indir1; break; case 2: func = TOK___bound_ptr_indir2; break; diff --git a/riscv64-gen.c b/riscv64-gen.c index 07adda5d..73ceefb0 100644 --- a/riscv64-gen.c +++ b/riscv64-gen.c @@ -681,7 +681,7 @@ ST_FUNC void gfunc_prolog(Sym *func_sym) } } sym_push(sym->v & ~SYM_FIELD, &sym->type, - (byref ? VT_LLOCAL : VT_LOCAL) | lvalue_type(sym->type.t), + (byref ? VT_LLOCAL : VT_LOCAL) | VT_LVAL, param_addr); } func_va_list_ofs = addr; diff --git a/tcc.h b/tcc.h index 867d4a4f..a61c5ba5 100644 --- a/tcc.h +++ b/tcc.h @@ -932,11 +932,6 @@ struct filespec { dereferencing value */ #define VT_BOUNDED 0x8000 /* value is bounded. The address of the bounding function call point is in vc */ -#define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */ -#define VT_LVAL_SHORT 0x2000 /* lvalue is a short */ -#define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */ -#define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED) - /* types */ #define VT_BTYPE 0x000f /* mask for basic type */ #define VT_VOID 0 /* void type */ @@ -1426,7 +1421,6 @@ ST_FUNC void vstore(void); ST_FUNC void inc(int post, int c); ST_FUNC void parse_mult_str (CString *astr, const char *msg); ST_FUNC void parse_asm_str(CString *astr); -ST_FUNC int lvalue_type(int t); ST_FUNC void indir(void); ST_FUNC void unary(void); ST_FUNC void expr_prod(void); diff --git a/tccgen.c b/tccgen.c index f966fcc2..f26dad9a 100644 --- a/tccgen.c +++ b/tccgen.c @@ -1408,7 +1408,7 @@ ST_FUNC void save_reg_upstack(int r, int n) p->c.i */ p->r = (p->r & ~(VT_VALMASK | VT_BOUNDED)) | VT_LLOCAL; } else { - p->r = lvalue_type(p->type.t) | VT_LOCAL; + p->r = VT_LVAL | VT_LOCAL; } p->r2 = VT_CONST; p->c.i = l; @@ -1430,7 +1430,7 @@ ST_FUNC int get_reg_ex(int rc, int rc2) n=0; for(p = vstack; p <= vtop; p++) { if ((p->r & VT_VALMASK) == r || - (p->r2 & VT_VALMASK) == r) + p->r2 == r) n++; } if (n <= 1) @@ -1454,7 +1454,7 @@ ST_FUNC int get_reg(int rc) return r; for(p=vstack;p<=vtop;p++) { if ((p->r & VT_VALMASK) == r || - (p->r2 & VT_VALMASK) == r) + p->r2 == r) goto notfound; } return r; @@ -1467,7 +1467,7 @@ ST_FUNC int get_reg(int rc) spill registers used in gen_opi()) */ for(p=vstack;p<=vtop;p++) { /* look at second register (if long long) */ - r = p->r2 & VT_VALMASK; + r = p->r2; if (r < VT_CONST && (reg_classes[r] & rc)) goto save_found; r = p->r & VT_VALMASK; @@ -1553,16 +1553,13 @@ ST_FUNC void gaddrof(void) vtop->r &= ~VT_LVAL; /* tricky: if saved lvalue, then we can go back to lvalue */ if ((vtop->r & VT_VALMASK) == VT_LLOCAL) - vtop->r = (vtop->r & ~(VT_VALMASK | VT_LVAL_TYPE)) | VT_LOCAL | VT_LVAL; - - + vtop->r = (vtop->r & ~VT_VALMASK) | VT_LOCAL | VT_LVAL; } #ifdef CONFIG_TCC_BCHECK /* generate lvalue bound code */ static void gbound(void) { - int lval_type; CType type1; vtop->r &= ~VT_MUSTBOUND; @@ -1570,14 +1567,13 @@ static void gbound(void) if (vtop->r & VT_LVAL) { /* if not VT_BOUNDED value, then make one */ if (!(vtop->r & VT_BOUNDED)) { - lval_type = vtop->r & (VT_LVAL_TYPE | VT_LVAL); /* must save type because we must set it to int to get pointer */ type1 = vtop->type; vtop->type.t = VT_PTR; gaddrof(); vpushi(0); gen_bounded_ptr_add(); - vtop->r |= lval_type; + vtop->r |= VT_LVAL; vtop->type = type1; } /* then check for dereferencing */ @@ -1603,12 +1599,10 @@ static void incr_bf_adr(int o) { vtop->type = char_pointer_type; gaddrof(); - vpushi(o); + vpushs(o); gen_op('+'); - vtop->type.t = (vtop->type.t & ~(VT_BTYPE|VT_DEFSIGN)) - | (VT_BYTE|VT_UNSIGNED); - vtop->r = (vtop->r & ~VT_LVAL_TYPE) - | (VT_LVAL_BYTE|VT_LVAL_UNSIGNED|VT_LVAL); + vtop->type.t = VT_BYTE | VT_UNSIGNED; + vtop->r |= VT_LVAL; } /* single-byte load mode for packed or otherwise unaligned bitfields */ @@ -1688,7 +1682,7 @@ static int adjust_bf(SValue *sv, int bit_pos, int bit_size) t = sv->type.ref->auxtype; if (t != -1 && t != VT_STRUCT) { sv->type.t = (sv->type.t & ~VT_BTYPE) | t; - sv->r = (sv->r & ~VT_LVAL_TYPE) | lvalue_type(sv->type.t); + sv->r |= VT_LVAL; } return t; } @@ -1824,23 +1818,6 @@ ST_FUNC int gv(int rc) vtop->r2 = r2; done: vtop->type.t = original_type; - } else if ((vtop->r & VT_LVAL) && !is_float(vtop->type.t)) { - int t1, t; - /* lvalue of scalar type : need to use lvalue type - because of possible cast */ - t = vtop->type.t; - t1 = t; - /* compute memory access type */ - if (vtop->r & VT_LVAL_BYTE) - t = VT_BYTE; - else if (vtop->r & VT_LVAL_SHORT) - t = VT_SHORT; - if (vtop->r & VT_LVAL_UNSIGNED) - t |= VT_UNSIGNED; - vtop->type.t = t; - load(r, vtop); - /* restore wanted type */ - vtop->type.t = t1; } else { if (vtop->r == VT_CMP) vset_VT_JMP(); @@ -2983,16 +2960,11 @@ static void gen_cast(CType *type) } #endif } - /* if lvalue and single word type, nothing to do because - the lvalue already contains the real type size (see - VT_LVAL_xxx constants) */ } + if ((vtop->r & VT_LVAL) + && (dbt & VT_BTYPE) != (sbt & VT_BTYPE)) + gv(RC_INT); } - } else if ((dbt & VT_BTYPE) == VT_PTR && !(vtop->r & VT_LVAL)) { - /* if we are casting between pointer types, - we must update the VT_LVAL_xxx size */ - vtop->r = (vtop->r & ~VT_LVAL_TYPE) - | (lvalue_type(type->ref->type.t) & VT_LVAL_TYPE); } vtop->type = *type; vtop->type.t &= ~ ( VT_CONSTANT | VT_VOLATILE | VT_ARRAY ); @@ -4850,23 +4822,6 @@ static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td) return ret; } -/* compute the lvalue VT_LVAL_xxx needed to match type t. */ -ST_FUNC int lvalue_type(int t) -{ - int bt, r; - r = VT_LVAL; - bt = t & VT_BTYPE; - if (bt == VT_BYTE || bt == VT_BOOL) - r |= VT_LVAL_BYTE; - else if (bt == VT_SHORT) - r |= VT_LVAL_SHORT; - else - return r; - if (t & VT_UNSIGNED) - r |= VT_LVAL_UNSIGNED; - return r; -} - /* indirection with full error checking and bound check */ ST_FUNC void indir(void) { @@ -4879,9 +4834,9 @@ ST_FUNC void indir(void) gv(RC_INT); vtop->type = *pointed_type(&vtop->type); /* Arrays and functions are never lvalues */ - if (!(vtop->type.t & VT_ARRAY) && !(vtop->type.t & VT_VLA) + if (!(vtop->type.t & (VT_ARRAY | VT_VLA)) && (vtop->type.t & VT_BTYPE) != VT_FUNC) { - vtop->r |= lvalue_type(vtop->type.t); + vtop->r |= VT_LVAL; /* if bound checking, the referenced pointer must be checked */ #ifdef CONFIG_TCC_BCHECK if (tcc_state->do_bounds_check) @@ -5087,7 +5042,7 @@ ST_FUNC void unary(void) r = VT_LOCAL; /* all except arrays are lvalues */ if (!(type.t & VT_ARRAY)) - r |= lvalue_type(type.t); + r |= VT_LVAL; memset(&ad, 0, sizeof(AttributeDef)); decl_initializer_alloc(&type, &ad, r, 1, 0, 0); } else { @@ -5549,7 +5504,7 @@ special_math_val: vtop->type.t |= qualifiers; /* an array is never an lvalue */ if (!(vtop->type.t & VT_ARRAY)) { - vtop->r |= lvalue_type(vtop->type.t); + vtop->r |= VT_LVAL; #ifdef CONFIG_TCC_BCHECK /* if bound checking, the referenced pointer must be checked */ if (tcc_state->do_bounds_check && (vtop->r & VT_VALMASK) != VT_LOCAL) @@ -7948,7 +7903,7 @@ found: type.ref->f = ad.f; } else if (!(type.t & VT_ARRAY)) { /* not lvalue if array */ - r |= lvalue_type(type.t); + r |= VT_LVAL; } has_init = (tok == '='); if (has_init && (type.t & VT_VLA)) diff --git a/x86_64-gen.c b/x86_64-gen.c index 5c3d2e32..6ee0eba8 100644 --- a/x86_64-gen.c +++ b/x86_64-gen.c @@ -678,16 +678,7 @@ ST_FUNC void gen_bounded_ptr_deref(void) if (nocode_wanted) return; - size = 0; - /* XXX: put that code in generic part of tcc */ - if (!is_float(vtop->type.t)) { - if (vtop->r & VT_LVAL_BYTE) - size = 1; - else if (vtop->r & VT_LVAL_SHORT) - size = 2; - } - if (!size) - size = type_size(&vtop->type, &align); + size = type_size(&vtop->type, &align); switch(size) { case 1: func = TOK___bound_ptr_indir1; break; case 2: func = TOK___bound_ptr_indir2; break; @@ -981,7 +972,7 @@ void gfunc_prolog(Sym *func_sym) gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr); } sym_push(sym->v & ~SYM_FIELD, type, - VT_LLOCAL | lvalue_type(type->t), addr); + VT_LLOCAL | VT_LVAL, addr); } else { if (reg_param_index < REGN) { /* save arguments passed by register */ @@ -995,7 +986,7 @@ void gfunc_prolog(Sym *func_sym) } } sym_push(sym->v & ~SYM_FIELD, type, - VT_LOCAL | lvalue_type(type->t), addr); + VT_LOCAL | VT_LVAL, addr); } addr += 8; reg_param_index++; @@ -1205,7 +1196,16 @@ static X86_64_Mode classify_x86_64_arg(CType *ty, CType *ret, int *psize, int *p ret_t = VT_QLONG; } else { *reg_count = 1; - ret_t = (size > 4) ? VT_LLONG : VT_INT; + if (size > 4) + ret_t = VT_LLONG; + else if (size > 2) + ret_t = VT_INT; + else if (size > 1) + ret_t = VT_SHORT; + else + ret_t = VT_BYTE; + if ((ty->t & VT_BTYPE) == VT_STRUCT || (ty->t & VT_UNSIGNED)) + ret_t |= VT_UNSIGNED; } break; @@ -1321,7 +1321,7 @@ void gfunc_call(int nb_args) tcc_error("SSE disabled but floating point arguments passed"); /* fetch cpu flag before generating any code */ - if (vtop >= vstack && (vtop->r & VT_VALMASK) == VT_CMP) + if ((vtop->r & VT_VALMASK) == VT_CMP) gv(RC_INT); /* for struct arguments, we need to call memcpy and the function @@ -1635,7 +1635,7 @@ void gfunc_prolog(Sym *func_sym) default: break; /* nothing to be done for x86_64_mode_none */ } sym_push(sym->v & ~SYM_FIELD, type, - VT_LOCAL | lvalue_type(type->t), param_addr); + VT_LOCAL | VT_LVAL, param_addr); } #ifdef CONFIG_TCC_BCHECK