1 /* Test to verify that calls to common built-in functions declared
2    with no prototype do not cause an ICE.
3   { dg-do compile }
4   { dg-options "-O2 -Wall -Wextra" }
5   { dg-prune-output "warning" }
6   { dg-require-effective-target alloca }  */
7 
8 typedef __SIZE_TYPE__ size_t;
9 
10 #if __cplusplus
11 extern "C" {
12 
13 #define NO_PROTO ...
14 #else
15 #define NO_PROTO /* empty */
16 #endif
17 
18   /* Character classification built-ins from <ctype.h>.  */
19   int isalpha (NO_PROTO);
20   int isalnum (NO_PROTO);
21   int isalpha (NO_PROTO);
22   int iscntrl (NO_PROTO);
23   int isdigit (NO_PROTO);
24   int isgraph (NO_PROTO);
25   int islower (NO_PROTO);
26   int isprint (NO_PROTO);
27   int ispunct (NO_PROTO);
28   int isspace (NO_PROTO);
29   int isupper (NO_PROTO);
30   int isxdigit (NO_PROTO);
31   int tolower (NO_PROTO);
32   int toupper (NO_PROTO);
33 
34   /* Memory allocation built-ins from <stdlib.h>.  */
35   void* alloca (NO_PROTO);
36   void* aligned_alloc (NO_PROTO);
37   void* calloc (NO_PROTO);
38   void* malloc (NO_PROTO);
39   void* realloc (NO_PROTO);
40 
41   /* Raw memory built-ins from <string.h>.  */
42   void* memcpy (NO_PROTO);
43   void* memchr (NO_PROTO);
44   void* memmove (NO_PROTO);
45   void* mempcpy (NO_PROTO);
46   void* memset (NO_PROTO);
47 
48   /* String built-ins from <string.h>.  */
49   char* stpcpy (NO_PROTO);
50   char* stpncpy (NO_PROTO);
51 
52   char* strcat (NO_PROTO);
53   char* strcpy (NO_PROTO);
54 
55   char* strdup (NO_PROTO);
56   char* strndup (NO_PROTO);
57 
58   char* strncat (NO_PROTO);
59   char* strncpy (NO_PROTO);
60 
61   size_t strlen (NO_PROTO);
62   size_t strnlen (NO_PROTO);
63 
test_arrays(void)64   char* strchr (NO_PROTO);
65   int strcmp (NO_PROTO);
66   int strncmp (NO_PROTO);
67 
68   /* Input/output functions from <stdio.h>.  */
69   int puts (NO_PROTO);
70   int fputs (NO_PROTO);
71 
72   int scanf (NO_PROTO);
73   int fscanf (NO_PROTO);
74   int sscanf (NO_PROTO);
75   int vfscanf (NO_PROTO);
76   int vsscanf (NO_PROTO);
77 
78   int printf (NO_PROTO);
79   int fprintf (NO_PROTO);
80   int sprintf (NO_PROTO);
81 
82   int snprintf (NO_PROTO);
83 
84   int vprintf (NO_PROTO);
85   int vfprintf (NO_PROTO);
86   int vsprintf (NO_PROTO);
87 
88   int vsnprintf (NO_PROTO);
89 
90 #if __cplusplus
91 }
92 #endif
93 
94 
95 #define CONCAT(a, b) a ## b
96 #define UNIQ_NAME(func, id) CONCAT (test_ ## func ## _, id)
97 
98 #define TEST_FUNC(func, arglist)		\
99   __typeof__ (func arglist)			\
100   UNIQ_NAME (func, __COUNTER__) (void) {	\
101     return func arglist;			\
102   }
103 
104 #define T1(func)				\
105   TEST_FUNC (func, ());				\
106   TEST_FUNC (func, (1));			\
107   TEST_FUNC (func, (""));			\
108   TEST_FUNC (func, ((void*)1));			\
test_pointers(void)109   TEST_FUNC (func, (iarr));			\
110   TEST_FUNC (func, (function))
111 
112 #define T2(func)				\
113   TEST_FUNC (func, (1, 1));			\
114   TEST_FUNC (func, (1, ""));			\
115   TEST_FUNC (func, (1, (void*)1));		\
116   TEST_FUNC (func, (1, iarr));			\
117   TEST_FUNC (func, (1, function))
118 
119 #define T3(func)				\
120   TEST_FUNC (func, (1, 1, 1));			\
121   TEST_FUNC (func, (1, 1, ""));			\
122   TEST_FUNC (func, (1, 1, (void*)1));		\
123   TEST_FUNC (func, (1, 1, iarr));		\
124   TEST_FUNC (func, (1, 1, function))
125 
126 extern int iarr[];
127 extern void function (void);
128 
129 T1 (isalpha);
130 T1 (isalnum);
131 T1 (isalpha);
132 T1 (iscntrl);
133 T1 (isdigit);
134 T1 (isgraph);
135 T1 (islower);
136 T1 (isprint);
137 T1 (ispunct);
138 T1 (isspace);
139 T1 (isupper);
140 T1 (isxdigit);
141 T1 (tolower);
142 T1 (toupper);
143 
144 T1 (alloca);
145 T2 (aligned_alloc);
146 T2 (malloc);
147 T2 (calloc);
148 T2 (realloc);
149 
150 T3 (memcpy);
151 T3 (memmove);
152 T3 (mempcpy);
153 T3 (memset);
154 T3 (memchr);
155 
156 T2 (stpcpy);
157 T3 (stpncpy);
158 
159 T2 (strcat);
160 T2 (strcpy);
161 
162 T1 (strdup);
163 T2 (strndup);
164 
165 T3 (strncat);
166 T3 (strncpy);
167 
168 T2 (strchr);
169 T2 (strcmp);
170 T3 (strncmp);
171 
172 T1 (strlen);
173 T2 (strnlen);
174 
175 T1 (puts);
176 T2 (fputs);
177 
178 T1 (scanf);
179 T2 (fscanf);
180 T2 (sscanf);
181 T2 (vfscanf);
182 T2 (vsscanf);
183 
184 T2 (printf);
185 T3 (fprintf);
186 T3 (sprintf);
187 
188 T3 (snprintf);
189 
190 T2 (vprintf);
191 T2 (vfprintf);
192 T2 (vsprintf);
193 
194 T3 (vsnprintf);
195