1/* { dg-do run } */
2/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
3/* { dg-options "-fsanitize=undefined" } */
4
5/* Test PARM_DECLs and RESULT_DECLs.  */
6
7struct T { char d[8]; int e; };
8struct T t = { "abcdefg", 1 };
9#ifdef __cplusplus
10struct C { C () : d("abcdefg"), e(1) {} C (const C &x) { __builtin_memcpy (d, x.d, 8); e = x.e; } ~C () {} char d[8]; int e; };
11#endif
12struct U { int a : 5; int b : 19; int c : 8; };
13struct S { struct U d[10]; };
14struct S s;
15
16int
17f1 (struct T x, int i)
18{
19  char *p = x.d;
20  p += i;
21  return *p;
22}
23
24/* { dg-output "load of address \[^\n\r]* with insufficient space for an object of type 'char'\[^\n\r]*(\n|\r\n|\r)" } */
25/* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" } */
26/* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" } */
27/* { dg-output "\[^\n\r]*\\^\[^\n\r]*(\n|\r\n|\r)" } */
28
29#ifdef __cplusplus
30struct C
31f2 (int i)
32{
33  struct C x;
34  x.d[i] = 'z';
35  return x;
36}
37
38/* { dg-output "\[^\n\r]*index 12 out of bounds for type 'char \\\[8\\\]'\[^\n\r]*(\n|\r\n|\r)" { target { c++ } } } */
39/* { dg-output "\[^\n\r]*store to address \[^\n\r]* with insufficient space for an object of type 'char'\[^\n\r]*(\n|\r\n|\r)" { target { c++ } } } */
40/* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" { target { c++ } } } */
41/* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" { target { c++ } } } */
42/* { dg-output "\[^\n\r]*\\^\[^\n\r]*(\n|\r\n|\r)" { target { c++ } } } */
43
44struct C
45f3 (int i)
46{
47  struct C x;
48  char *p = x.d;
49  p += i;
50  *p = 'z';
51  return x;
52}
53
54/* { dg-output "\[^\n\r]*store to address \[^\n\r]* with insufficient space for an object of type 'char'\[^\n\r]*(\n|\r\n|\r)" { target { c++ } } } */
55/* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" { target { c++ } } } */
56/* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" { target { c++ } } } */
57/* { dg-output "\[^\n\r]*\\^\[^\n\r]*(\n|\r\n|\r)" { target { c++ } } } */
58
59#endif
60
61int
62f4 (int i)
63{
64  return s.d[i].b;
65}
66
67/* { dg-output "\[^\n\r]*index 12 out of bounds for type 'U \\\[10\\\]'\[^\n\r]*(\n|\r\n|\r)" } */
68/* { dg-output "\[^\n\r]*load of address \[^\n\r]* with insufficient space for an object of type 'unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
69/* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" } */
70/* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" } */
71/* { dg-output "\[^\n\r]*\\^\[^\n\r]*(\n|\r\n|\r)" } */
72
73int
74f5 (int i)
75{
76  struct U *u = s.d;
77  u += i;
78  return u->b;
79}
80
81/* { dg-output "\[^\n\r]*load of address \[^\n\r]* with insufficient space for an object of type 'unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
82/* { dg-output "\[^\n\r]*note: pointer points here\[^\n\r]*(\n|\r\n|\r)" } */
83/* { dg-output "\[^\n\r]*\[^\n\r]*(\n|\r\n|\r)" } */
84/* { dg-output "\[^\n\r]*\\^\[^\n\r]*(\n|\r\n|\r)" } */
85
86int
87main (void)
88{
89  f1 (t, 12);
90#ifdef __cplusplus
91  f2 (12);
92  f3 (12);
93#endif
94  f4 (12);
95  f5 (12);
96  return 0;
97}
98