Fix test failures for enum-alias-{1,2,3} on arm-eabi [PR117419]
[official-gcc.git] / gcc / testsuite / c-c++-common / ubsan / object-size-9.c
blobbd2a53e643946d15b09df33dd5c98f98b44d16b2
1 /* { dg-do run } */
2 /* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */
3 /* { dg-options "-Wno-stringop-overflow -fsanitize=undefined" } */
5 /* Test PARM_DECLs and RESULT_DECLs. */
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)));
16 int
17 f1 (struct T x, int i)
19 char *p = x.d;
20 p += i;
21 return *p;
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)" } */
29 #ifdef __cplusplus
30 static struct C
31 f2 (int i)
33 struct C x;
34 x.d[i] = 'z';
35 return x;
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++ } } } */
44 static struct C
45 f3 (int i)
47 struct C x;
48 char *p = x.d;
49 p += i;
50 *p = 'z';
51 return x;
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++ } } } */
59 #endif
61 int
62 f4 (int i)
64 return s.d[i].b;
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)" } */
73 int
74 f5 (int i)
76 struct U *u = s.d;
77 u += i;
78 return u->b;
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]*\\^" } */
86 int
87 main (void)
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;