History

Fix "Add support for struct > 4B returned via registers"

- avoid assumption "ret_align == register_size" which is false for non-arm targets - rename symbol "sret" to more descriptive "ret_nregs" This fixes commit dcec8673f21da86ae3dcf1ca3e9498127715b795

grischka committed 12 years ago

Commit fbc88101 parent 46dd2973 files · +31 −16Browse files

Unified · Split

3 files
  1. i386-gen.c +1 −1
  2. tccgen.c +28 −15
  3. win32/include/math.h +2 −0
i386-gen.c+1−1
@@ -392,7 +392,7 @@ ST_FUNC int gfunc_sret(CType *vt, CType *ret, int *ret_align) · 391 unmodified lines
392392 } else {
393393 ret->ref = NULL;
394394 ret->t = VT_INT;
395− return 0;
395+ return 1;
396396 }
397397 #else
398398 *ret_align = 1; // Never have to re-align return values for x86
tccgen.c+28−15
@@ -3927,7 +3927,7 @@ ST_FUNC void unary(void) · 3926 unmodified lines
39273927 } else if (tok == '(') {
39283928 SValue ret;
39293929 Sym *sa;
3930− int nb_args, sret, ret_align;
3930+ int nb_args, ret_nregs, ret_align;
39313931
39323932 /* function call */
39333933 if ((vtop->type.t & VT_BTYPE) != VT_FUNC) {
@@ -3951,8 +3951,8 @@ ST_FUNC void unary(void) · 17 unmodified lines
39513951 ret.r2 = VT_CONST;
39523952 /* compute first implicit argument if a structure is returned */
39533953 if ((s->type.t & VT_BTYPE) == VT_STRUCT) {
3954− sret = gfunc_sret(&s->type, &ret.type, &ret_align);
3955− if (!sret) {
3954+ ret_nregs = gfunc_sret(&s->type, &ret.type, &ret_align);
3955+ if (!ret_nregs) {
39563956 /* get some space for the returned structure */
39573957 size = type_size(&s->type, &align);
39583958 loc = (loc - size) & -align;
@@ -3965,11 +3965,11 @@ ST_FUNC void unary(void) · 6 unmodified lines
39653965 nb_args++;
39663966 }
39673967 } else {
3968− sret = 1;
3968+ ret_nregs = 1;
39693969 ret.type = s->type;
39703970 }
39713971
3972− if (sret) {
3972+ if (ret_nregs) {
39733973 /* return in register */
39743974 if (is_float(ret.type.t)) {
39753975 ret.r = reg_fret(ret.type.t);
@@ -4008,23 +4008,30 @@ ST_FUNC void unary(void) · 32 unmodified lines
40084008 } else {
40094009 vtop -= (nb_args + 1);
40104010 }
4011+
40114012 /* return value */
4012− for (r = ret.r + sret + !sret; r-- > ret.r;) {
4013+ for (r = ret.r + ret_nregs + !ret_nregs; r-- > ret.r;) {
40134014 vsetc(&ret.type, r, &ret.c);
40144015 vtop->r2 = ret.r2; /* Loop only happens when r2 is VT_CONST */
40154016 }
4017+
40164018 /* handle packed struct return */
4017− if (((s->type.t & VT_BTYPE) == VT_STRUCT) && sret) {
4019+ if (((s->type.t & VT_BTYPE) == VT_STRUCT) && ret_nregs) {
40184020 int addr, offset;
40194021
40204022 size = type_size(&s->type, &align);
40214023 loc = (loc - size) & -align;
40224024 addr = loc;
4023− for(offset = 0; offset < size; offset += ret_align) {
4025+ offset = 0;
4026+ for (;;) {
40244027 vset(&ret.type, VT_LOCAL | VT_LVAL, addr + offset);
40254028 vswap();
40264029 vstore();
40274030 vtop--;
4031+ if (--ret_nregs == 0)
4032+ break;
4033+ /* XXX: compatible with arm only: ret_align == register_size */
4034+ offset += ret_align;
40284035 }
40294036 vset(&s->type, VT_LOCAL | VT_LVAL, addr);
40304037 }
@@ -4596,8 +4603,9 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 565 unmodified lines
45964603 gen_assign_cast(&func_vt);
45974604 if ((func_vt.t & VT_BTYPE) == VT_STRUCT) {
45984605 CType type, ret_type;
4599− int ret_align;
4600− if (!gfunc_sret(&func_vt, &ret_type, &ret_align)) {
4606+ int ret_align, ret_nregs;
4607+ ret_nregs = gfunc_sret(&func_vt, &ret_type, &ret_align);
4608+ if (0 == ret_nregs) {
46014609 /* if returning structure, must copy it to implicit
46024610 first pointer arg location */
46034611 type = func_vt;
@@ -4609,7 +4617,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 5 unmodified lines
46094617 vstore();
46104618 } else {
46114619 /* returning structure packed into registers */
4612− int r, size, addr, offset, align;
4620+ int r, size, addr, align;
46134621 size = type_size(&func_vt,&align);
46144622 if ((vtop->r != (VT_LOCAL | VT_LVAL) || (vtop->c.i & (ret_align-1)))
46154623 && (align & (ret_align-1))) {
@@ -4626,11 +4634,16 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym, · 10 unmodified lines
46264634 r = rc_fret(ret_type.t);
46274635 else
46284636 r = RC_IRET;
4629− /* We assume that when a structure is returned in multiple
4630− registers, their classes are consecutive values of the
4631− suite s(n) = 2^n */
4632− for (offset = 0; offset < size; offset += ret_align, r<<=1) {
4637+
4638+ for (;;) {
46334639 gv(r);
4640+ if (--ret_nregs == 0)
4641+ break;
4642+ /* We assume that when a structure is returned in multiple
4643+ registers, their classes are consecutive values of the
4644+ suite s(n) = 2^n */
4645+ r <<= 1;
4646+ /* XXX: compatible with arm only: ret_align == register_size */
46344647 vtop->c.i += ret_align;
46354648 vtop->r = VT_LOCAL | VT_LVAL;
46364649 }
win32/include/math.h+2−0
@@ -666,6 +666,7 @@ extern "C" { · 665 unmodified lines
666666 extern long double __cdecl fmal (long double, long double, long double);
667667
668668
669+#if 0 // gr: duplicate, see below
669670 /* 7.12.14 */
670671 /*
671672 * With these functions, comparisons involving quiet NaNs set the FP
@@ -708,6 +709,7 @@ extern "C" { · 36 unmodified lines
708709 & 0x4500) == 0x4500)
709710
710711 #endif
712+#endif //0
711713
712714
713715 #endif /* __STDC_VERSION__ >= 199901L */

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