Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / gcc.dg / uninit-41.c
blobf2e17a81d0922e94799dc9702a763ff740dceb24
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 } */
7 typedef __SIZE_TYPE__ size_t;
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*);
20 void noproto ();
22 void sink (int, ...);
24 extern char a[];
26 void nowarn_noproto (const char *fmt)
28 int i;
29 noproto (&i);
30 sink (i);
33 void nowarn_scanf (const char *fmt)
35 int i;
36 scanf ("%i", &i);
37 sink (i);
40 void test_puts_sprintf_alloca (const char *fmt)
42 char *p;
44 p = alloca (8);
45 sprintf (a, fmt, p); // fmt might contain %n
46 puts (p);
50 p = alloca (8);
51 snprintf (0, 0, fmt, p); // same as above
52 puts (p);
56 void test_puts_alloca (const char *s)
58 char *p = alloca (8);
61 char a[] = "foo";
62 puts (a);
65 puts (p); // { dg-warning "-Wuninitialized" }
68 p = alloca (strlen (s) + 1);
69 strcpy (p, s);
70 puts (p);
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" }
83 void test_puts_malloc (const char *s, const char *t)
85 char *p;
88 p = malloc (strlen (s) + 1);
89 strcpy (p, s);
90 puts (p);
94 p = malloc (strlen (t));
95 puts (p); // { dg-warning "-Wuninitialized" }
100 void test_puts_vla (const char *s, const char *t)
103 char a[strlen (s) + 1];
104 strcpy (a, s);
105 puts (a);
109 char b[strlen (t)];
110 puts (b); // { dg-warning "-Wuninitialized" }
115 void test_printf_puts (const char *s)
117 char *p = __builtin_malloc (1);
119 printf ("%s", s);
121 puts (p); // { dg-warning "-Wuninitialized" }