]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/Wstringop-overflow-71.c
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.
5 { dg-options "-O2" } */
7 typedef __INT16_TYPE__
int16_t;
8 typedef __SIZE_TYPE__
size_t;
12 extern void* alloca (size_t);
14 extern double nan (const char *);
17 _Decimal32
nand32 (const char *);
19 /* _Decimal32 is supported only conditionally and not available on all
21 # define _Decimal32 double
22 # define nand32(s) nan (s)
25 extern size_t strlen (const char *);
26 extern char* strcpy (char *, const char *);
29 extern unsigned char ax
[], a1
[1], a2
[2], a8
[8];
32 void nowarn_abs (int i
)
35 *(char *)a1
= abs (i
);
40 *(int *)a1
= abs (i
); // { dg-warning "\\\[-Wstringop-overflow" }
44 void nowarn_alloca (size_t n
)
46 *(void **)ax
= alloca (n
);
49 void warn_alloca (size_t n
)
51 *(void **)a1
= alloca (n
); // { dg-warning "\\\[-Wstringop-overflow" }
55 void nowarn_complex (double x
, double i
)
57 *(_Complex
double *)ax
= __builtin_complex (x
, i
);
60 void warn_complex (double x
, double i
)
62 _Complex
double *p
= (_Complex
double *)a1
;
63 *p
= __builtin_complex (x
, i
); // { dg-warning "\\\[-Wstringop-overflow" "pr101455" { xfail *-*-* } }
67 __attribute__ ((noipa
)) void nowarn_nan (const char *s
)
69 *(double *)ax
= nan (s
);
72 __attribute__ ((noipa
)) void warn_nan (const char *s
)
74 *(double *)a1
= nan (s
); // { dg-warning "\\\[-Wstringop-overflow" }
78 __attribute__ ((noipa
)) void nowarn_nand32 (const char *s
)
80 *(_Decimal32
*)ax
= nand32 (s
);
83 __attribute__ ((noipa
)) void warn_nand32 (const char *s
)
85 *(_Decimal32
*)a1
= nand32 (s
); // { dg-warning "\\\[-Wstringop-overflow" }
89 void nowarn_strlen (const char *s1
, const char *s2
, const char *s3
)
91 *(char *)ax
= strlen (s1
);
92 *(char *)a1
= strlen (s2
);
93 *(size_t *)a8
= strlen (s3
);
96 void warn_strlen (const char *s1
, const char *s2
)
98 *(int16_t *)a1
= strlen (s1
); // { dg-warning "\\\[-Wstringop-overflow" }
99 *(size_t *)a2
= strlen (s2
); // { dg-warning "\\\[-Wstringop-overflow" "!ptr_eq_short" { target { ! ptr_eq_short } } }
103 void nowarn_strcpy (char *s1
, char *s2
, const char *s3
)
105 *(char **)ax
= strcpy (s1
, s2
);
106 *(char **)a8
= strcpy (s2
, s3
);
109 void warn_strcpy (char *s1
, char *s2
, const char *s3
)
111 *(char **)a1
= strcpy (s1
, s2
); // { dg-warning "\\\[-Wstringop-overflow" }
112 *(char **)a2
= strcpy (s2
, s3
); // { dg-warning "\\\[-Wstringop-overflow" "!ptr_eq_short" { target { ! ptr_eq_short } } }