]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-25.c
Fix profile update in tree_transform_and_unroll_loop
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / builtin-sprintf-warn-25.c
CommitLineData
d02c41dd
MS
1/* PR middle-end/97373 - missing warning on sprintf into allocated destination
2 { dg-do compile }
893aeac1
TV
3 { dg-options "-O2 -Wall -ftrack-macro-expansion=0" }
4 { dg-require-effective-target alloca } */
d02c41dd
MS
5
6#include "../range.h"
7
8extern void* alloca (size_t);
9extern void* malloc (size_t);
10
11extern int sprintf (char*, const char*, ...);
12#define sprintf(d, ...) (sprintf (d, __VA_ARGS__), sink (d))
13
14void sink (void*, ...);
15
16void test_alloca_range (void)
17{
18 int n1_2 = UR (1, 2);
19 int n5_9 = UR (5, 9);
20
21 char *d = (char*)alloca (n5_9);
22
23 sprintf (d, "%i", 12345);
24
25 d += n1_2;
26 sprintf (d, "%i", 12345);
27
28 d += n1_2;
29 sprintf (d, "%i", 12345);
30
31 d += n1_2;
32 sprintf (d, "%i", 12345);
33
34 d += n1_2;
35 sprintf (d, "%i", 12345); // { dg-warning "writing a terminating nul past the end of the destination" }
36
37 d += n1_2;
38 sprintf (d, "%i", 12345); // { dg-warning "'%i' directive writing 5 bytes into a region of size 4" }
39}
40
41
42void test_malloc_range (void)
43{
44 int n2_3 = UR (2, 3);
45 int n5_9 = UR (5, 9);
46
47 char *d = (char*)malloc (n5_9);
48
49 sprintf (d, "%i", 12345);
50
51 d += n2_3;
52 sprintf (d, "%i", 12345);
53
54 d += n2_3;
55 sprintf (d, "%i", 12345); // { dg-warning "writing a terminating nul past the end of the destination" }
56
57 d += n2_3;
58 sprintf (d, "%i", 12345); // { dg-warning "'%i' directive writing 5 bytes into a region of size 3" }
59}
60
61
62void test_vla_range (void)
63{
64 int n3_4 = UR (3, 4);
65 int n5_9 = UR (5, 9);
66
67 char vla[n5_9];
68 char *d = vla;
69
70 sprintf (d, "%i", 12345);
71
72 d += n3_4;
73 sprintf (d, "%i", 12345);
74
75 d += n3_4;
76 sprintf (d, "%i", 12345); // { dg-warning "'%i' directive writing 5 bytes into a region of size 3" }
77}