c++: Implement for namespace statics CWG 2867 - Order of initialization for structure...
[official-gcc.git] / gcc / testsuite / gcc.dg / Wstringop-overflow-71.c
blob74311ecf7ff47c7fab4ca610c544d236d32da3ce
1 /* PR tree-optimization/97027 - missing warning on buffer overflow storing
2 a larger scalar into a smaller array
3 Verify warnings for overflow by stores of results of built-in functions.
4 { dg-do compile }
5 { dg-options "-O2" }
6 { dg-require-effective-target alloca } */
8 typedef __INT16_TYPE__ int16_t;
9 typedef __SIZE_TYPE__ size_t;
11 extern int abs (int);
13 extern void* alloca (size_t);
15 extern double nan (const char *);
17 #ifdef __DEC32_MAX__
18 _Decimal32 nand32 (const char *);
19 #else
20 /* _Decimal32 is supported only conditionally and not available on all
21 targets. */
22 # define _Decimal32 double
23 # define nand32(s) nan (s)
24 #endif
26 extern size_t strlen (const char *);
27 extern char* strcpy (char *, const char *);
30 extern unsigned char ax[], a1[1], a2[2], a8[8];
33 void nowarn_abs (int i)
35 *(int *)ax = abs (i);
36 *(char *)a1 = abs (i);
39 void warn_abs (int i)
41 *(int *)a1 = abs (i); // { dg-warning "\\\[-Wstringop-overflow" }
45 void nowarn_alloca (size_t n)
47 *(void **)ax = alloca (n);
50 void warn_alloca (size_t n)
52 *(void **)a1 = alloca (n); // { dg-warning "\\\[-Wstringop-overflow" }
56 void nowarn_complex (double x, double i)
58 *(_Complex double *)ax = __builtin_complex (x, i);
61 void warn_complex (double x, double i)
63 _Complex double *p = (_Complex double *)a1;
64 *p = __builtin_complex (x, i); // { dg-warning "\\\[-Wstringop-overflow" "pr101455" { xfail *-*-* } }
68 __attribute__ ((noipa)) void nowarn_nan (const char *s)
70 *(double *)ax = nan (s);
73 __attribute__ ((noipa)) void warn_nan (const char *s)
75 *(double *)a1 = nan (s); // { dg-warning "\\\[-Wstringop-overflow" }
79 __attribute__ ((noipa)) void nowarn_nand32 (const char *s)
81 *(_Decimal32 *)ax = nand32 (s);
84 __attribute__ ((noipa)) void warn_nand32 (const char *s)
86 *(_Decimal32 *)a1 = nand32 (s); // { dg-warning "\\\[-Wstringop-overflow" }
90 void nowarn_strlen (const char *s1, const char *s2, const char *s3)
92 *(char *)ax = strlen (s1);
93 *(char *)a1 = strlen (s2);
94 *(size_t *)a8 = strlen (s3);
97 void warn_strlen (const char *s1, const char *s2)
99 *(int16_t *)a1 = strlen (s1); // { dg-warning "\\\[-Wstringop-overflow" }
100 *(size_t *)a2 = strlen (s2); // { dg-warning "\\\[-Wstringop-overflow" "!ptr_eq_short" { target { ! ptr_eq_short } } }
104 void nowarn_strcpy (char *s1, char *s2, const char *s3)
106 *(char **)ax = strcpy (s1, s2);
107 *(char **)a8 = strcpy (s2, s3);
110 void warn_strcpy (char *s1, char *s2, const char *s3)
112 *(char **)a1 = strcpy (s1, s2); // { dg-warning "\\\[-Wstringop-overflow" }
113 *(char **)a2 = strcpy (s2, s3); // { dg-warning "\\\[-Wstringop-overflow" "!ptr_eq_short" { target { ! ptr_eq_short } } }