1 /* Verify that calls to non-modifying built-ins aren't considered
2 potentially modifying.
3 { dg-do compile }
4 { dg-options "-O2 -Wall" }
5 { dg-require-effective-target alloca } */
6
7 typedef __SIZE_TYPE__ size_t;
8
9 void* alloca (size_t);
10 void* calloc (size_t, size_t);
11 void* malloc (size_t);
12 int printf (const char *, ...);
13 int scanf (const char *, ...);
14 int sprintf (char *, const char *, ...);
15 int snprintf (char *, size_t, const char *, ...);
16 int puts (const char *);
17 char* strcpy (char*, const char*);
18 size_t strlen (const char*);
19
20 void noproto ();
21
22 void sink (int, ...);
23
24 extern char a[];
25
26 void nowarn_noproto (const char *fmt)
27 {
28 int i;
29 noproto (&i);
30 sink (i);
31 }
32
33 void nowarn_scanf (const char *fmt)
34 {
35 int i;
36 scanf ("%i", &i);
37 sink (i);
38 }
39
40 void test_puts_sprintf_alloca (const char *fmt)
41 {
42 char *p;
43 {
44 p = alloca (8);
45 sprintf (a, fmt, p); // fmt might contain %n
46 puts (p);
47 }
48
49 {
50 p = alloca (8);
51 snprintf (0, 0, fmt, p); // same as above
52 puts (p);
53 }
54 }
55
56 void test_puts_alloca (const char *s)
57 {
58 char *p = alloca (8);
59
60 {
61 char a[] = "foo";
62 puts (a);
63 }
64
65 puts (p); // { dg-warning "-Wuninitialized" }
66
67 {
68 p = alloca (strlen (s) + 1);
69 strcpy (p, s);
70 puts (p);
71 }
72
73 {
74 /* Verify that the puts() calls above isn't considered to have
75 potentially modified *P, and same for the one below. */
76 p = alloca (strlen (s));
77 puts (p); // { dg-warning "-Wuninitialized" }
78 puts (p + 1); // { dg-warning "-Wuninitialized" }
79 }
80 }
81
82
83 void test_puts_malloc (const char *s, const char *t)
84 {
85 char *p;
86
87 {
88 p = malloc (strlen (s) + 1);
89 strcpy (p, s);
90 puts (p);
91 }
92
93 {
94 p = malloc (strlen (t));
95 puts (p); // { dg-warning "-Wuninitialized" }
96 }
97 }
98
99
100 void test_puts_vla (const char *s, const char *t)
101 {
102 {
103 char a[strlen (s) + 1];
104 strcpy (a, s);
105 puts (a);
106 }
107
108 {
109 char b[strlen (t)];
110 puts (b); // { dg-warning "-Wuninitialized" }
111 }
112 }
113
114
115 void test_printf_puts (const char *s)
116 {
117 char *p = __builtin_malloc (1);
118
119 printf ("%s", s);
120
121 puts (p); // { dg-warning "-Wuninitialized" }
122 }