mirror of
https://github.com/mirror/tinycc.git
synced 2026-08-22 11:23:27 +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:
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
|
||||
Reference in New Issue
Block a user