Debian Codegraph @

gcc/testsuite/g++.dg/hwasan/rvo-handled.C

raw
1 /* { dg-do run } */
2 /* { dg-require-effective-target hwaddress_exec } */
3 /* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
4
5 #define assert(x) if (!(x)) __builtin_abort ()
6 typedef __UINTPTR_TYPE__ uintptr_t;
7 void *untagged (void *ptr)
8 {
9 /* Untag by removing the top byte. */
10 return (void*)((uintptr_t)ptr & 0xffffffffffffff);
11 }
12
13 struct big_struct {
14 int left;
15 int right;
16 void *ptr;
17 int big_array[100];
18 };
19
20 /*
21 Tests for RVO (basically, checking -fsanitize=hwaddress has not broken RVO
22 in any way).
23
24 0) The value is accessible in both functions without a hwasan complaint.
25 1) RVO does happen.
26 */
27
28 struct big_struct __attribute__ ((noinline))
29 return_on_stack()
30 {
31 struct big_struct x;
32 x.left = 100;
33 x.right = 20;
34 x.big_array[10] = 30;
35 x.ptr = untagged(&x);
36 return x;
37 }
38
39 int main()
40 {
41 struct big_struct x;
42 x = return_on_stack();
43 /* Check that RVO happens by checking the address that the callee saw. */
44 assert (x.ptr == untagged(&x));
45 return 0;
46 }