111
|
1 /* { dg-do run } */
|
|
2 /* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
|
145
|
3 /* { dg-options "-Wno-stringop-overflow -fsanitize=undefined" } */
|
111
|
4
|
|
5 /* Test PARM_DECLs and RESULT_DECLs. */
|
|
6
|
|
7 struct T { char d[8]; int e; };
|
|
8 struct T t = { "abcdefg", 1 };
|
|
9 #ifdef __cplusplus
|
|
10 struct 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
|
|
12 struct U { int a : 5; int b : 19; int c : 8; };
|
|
13 struct S { struct U d[10]; };
|
|
14 struct S s __attribute__ ((aligned(4096)));
|
|
15
|
|
16 int
|
|
17 f1 (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
|
|
30 static struct C
|
|
31 f2 (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
|
|
44 static struct C
|
|
45 f3 (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
|
|
61 int
|
|
62 f4 (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
|
|
73 int
|
|
74 f5 (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]*\\^" } */
|
|
85
|
|
86 int
|
|
87 main (void)
|
|
88 {
|
|
89 f1 (t, 12);
|
|
90 #ifdef __cplusplus
|
|
91 f2 (12);
|
|
92 f3 (12);
|
|
93 #endif
|
|
94 f4 (12);
|
|
95 f5 (12);
|
|
96 #ifdef __cplusplus
|
|
97 /* Stack may be smashed by f2/f3 above. */
|
|
98 __builtin_exit (0);
|
|
99 #endif
|
|
100 return 0;
|
|
101 }
|