mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-29 06:10:09 +08:00
Fix invalid load generated by gfunc_return()
On backends that rely on gfunc_return() to handle structures returned in registers (like RISC-V), gfunc_return() may generate invalid loads for structures without VT_LOCAL and VT_LVAL. This commit fixes it and adds a regression test (131_return_struct_in_reg)
This commit is contained in:
parent
c92f4f52d9
commit
a82aff3337
2
tccgen.c
2
tccgen.c
@ -6622,7 +6622,7 @@ static void gfunc_return(CType *func_type)
|
||||
size = type_size(func_type,&align);
|
||||
if ((vtop->r != (VT_LOCAL | VT_LVAL) ||
|
||||
(vtop->c.i & (ret_align-1)))
|
||||
&& (align & (ret_align-1))) {
|
||||
|| (align & (ret_align-1))) {
|
||||
loc = (loc - size) & -ret_align;
|
||||
addr = loc;
|
||||
type = *func_type;
|
||||
|
49
tests/tests2/131_return_struct_in_reg.c
Normal file
49
tests/tests2/131_return_struct_in_reg.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include<stdio.h>
|
||||
|
||||
#define DATA 0x1234567890abcd, 0x5a5aa5a5f0f00f0f
|
||||
|
||||
struct s {
|
||||
long int a;
|
||||
long int b;
|
||||
};
|
||||
|
||||
struct {
|
||||
struct s d;
|
||||
} g = { { DATA } }, *gp = &g;
|
||||
|
||||
struct s
|
||||
foo1(void)
|
||||
{
|
||||
struct s d = { DATA };
|
||||
struct s *p = &d;
|
||||
long int x = 0;
|
||||
return *p;
|
||||
}
|
||||
|
||||
struct s
|
||||
foo2(void)
|
||||
{
|
||||
long int unused = 0;
|
||||
return gp->d;
|
||||
}
|
||||
|
||||
struct s
|
||||
foo3(void)
|
||||
{
|
||||
struct s d = { DATA };
|
||||
long int unused = 0;
|
||||
return d;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
struct s d;
|
||||
d = foo1();
|
||||
printf("%lx %lx\n", d.a, d.b);
|
||||
d = foo2();
|
||||
printf("%lx %lx\n", d.a, d.b);
|
||||
d = foo3();
|
||||
printf("%lx %lx\n", d.a, d.b);
|
||||
return 0;
|
||||
}
|
3
tests/tests2/131_return_struct_in_reg.expect
Normal file
3
tests/tests2/131_return_struct_in_reg.expect
Normal file
@ -0,0 +1,3 @@
|
||||
1234567890abcd 5a5aa5a5f0f00f0f
|
||||
1234567890abcd 5a5aa5a5f0f00f0f
|
||||
1234567890abcd 5a5aa5a5f0f00f0f
|
Loading…
Reference in New Issue
Block a user