1 /* Copyright (C) 2006 Free Software Foundation, Inc. */
2 /* Contributed by Carlos O'Donell on 2006-03-14 */
4 /* Test that GCC follows the SPARC 32-bit psABI with regards to
5 structure return checking in a callee. When -mstd-struct-return
6 is specificed then gcc will emit code to skip the unimp insn. */
8 /* Origin: Carlos O'Donell <carlos@codesourcery.com> */
9 /* { dg-do run { target sparc*-*-solaris* sparc*-*-linux* sparc*-*-*bsd* } } */
10 /* { dg-options "-mstd-struct-return" } */
11 /* { dg-require-effective-target ilp32 } */
16 /* Local declaration of div_t structure */
22 /* Global check variable used by signal handler */
24 struct mydiv_t dcheck
;
26 struct mydiv_t
foo (void)
34 void handle_sigill (int signum
)
36 if (signum
== SIGILL
&& check
== 2)
38 /* We expected a SIGILL due to a mismatch in unimp size
39 and struct mydiv_t size */
46 /* Implement 3 checks to validate SPARC 32-bit psABI callee
49 Test1: Save area is valid. unimp size is valid.
50 Success: Save area modified correctly.
51 Failure: Save area unmodified.
53 Test2: Save area is valid. unimp size is invalid (invalid insn).
54 Success: Save area unmodified. check == 2.
55 Failure: Save area modified or check == 1.
57 Test3: Save area is invalid. unimp size is invalid (invalid size).
58 Success: Will raise a SIGILL.
59 Failure: SIGSEGV caused by write to invalid save area. */
67 /* Insert a call, insert unimp by hand */
68 __asm__ ("st %1, [ %%sp + 0x40 ]\n\t"
73 : "r" (&dcheck
), "i" (sizeof(struct mydiv_t
))
76 /* If the caller doesn't adjust the return, then it crashes.
77 Check the result too. */
79 if ((dcheck
.rem
!= 3) || (dcheck
.quot
!=4))
87 /* Ignore the return of the function */
88 __asm__ ("st %3, [ %%sp + 0x40 ]\n\t"
92 : "+r" (check
), "=m" (dcheck
)
93 : "i" (0x2), "r" (&dcheck
)
96 /* If the caller does an unconditional adjustment it will skip
97 the mov, and then we can fail the test based on check's value
98 We pass a valid pointer to a save area in order to check if
99 caller incorrectly wrote to the save area as well. There may
100 be a case where the unimp check and skip is correct, but the
101 write to the save area still occurs. */
106 if ((dcheck
.rem
!= 1) || (dcheck
.quot
!= 2))
110 /* Prepare a test that must SIGILL. According to the spec
111 if the sizes of the save area and return don't match then
112 the copy is ignored and we return to the unimp. */
114 signal (SIGILL
, handle_sigill
);
116 __asm__ ("st %%g0, [ %%sp + 0x40 ]\n\t"
121 : "i" (sizeof(struct mydiv_t
)-1)