Daily bump.
[official-gcc.git] / gcc / testsuite / gcc.dg / nonnull-3.c
blobc52fe2c830c800a4e2126be2fb4f9859ae21692d
1 /* Test for the "nonnull" function attribute on builtins. Use the
2 "__builtin_" style below so we don't need prototypes. */
3 /* Origin: Kaveh R. Ghazi <ghazi@caip.rutgers.edu> */
4 /* { dg-do compile } */
5 /* { dg-options "-Wnonnull" } */
7 #include <stddef.h>
9 void
10 foo (void *p, char *s)
12 __builtin_bzero (NULL, 0); /* { dg-warning "null" "pr80936" } */
13 __builtin_bcopy (NULL, p, 0); /* { dg-warning "null" "pr80936" } */
14 __builtin_bcopy (p, NULL, 0); /* { dg-warning "null" "pr80936" } */
15 __builtin_bcmp (NULL, p, 0); /* { dg-warning "null" "pr80936" } */
16 __builtin_bcmp (p, NULL, 0); /* { dg-warning "null" "pr80936" } */
17 __builtin_index (NULL, 16); /* { dg-warning "null" "null pointer check" } */
18 __builtin_rindex (NULL, 16); /* { dg-warning "null" "null pointer check" } */
20 __builtin_memcpy (p, NULL, 16); /* { dg-warning "null" "null pointer check" } */
21 __builtin_memcpy (NULL, p, 16); /* { dg-warning "null" "null pointer check" } */
22 __builtin_memmove (p, NULL, 16); /* { dg-warning "null" "null pointer check" } */
23 __builtin_memmove (NULL, p, 16); /* { dg-warning "null" "null pointer check" } */
24 __builtin_memcmp (p, NULL, 16); /* { dg-warning "null" "null pointer check" } */
25 __builtin_memcmp (NULL, p, 16); /* { dg-warning "null" "null pointer check" } */
26 __builtin_memset (NULL, 0, 16); /* { dg-warning "null" "null pointer check" } */
27 __builtin_mempcpy (p, NULL, 16); /* { dg-warning "null" "null pointer check" } */
28 __builtin_mempcpy (NULL, p, 16); /* { dg-warning "null" "null pointer check" } */
30 __builtin_strcat (NULL, s); /* { dg-warning "null" "null pointer check" } */
31 __builtin_strcat (s, NULL); /* { dg-warning "null" "null pointer check" } */
32 __builtin_strncat (NULL, s, 16); /* { dg-warning "null" "null pointer check" } */
33 __builtin_strncat (s, NULL, 16); /* { dg-warning "null" "null pointer check" } */
34 __builtin_stpcpy (NULL, s); /* { dg-warning "null" "null pointer check" } */
35 __builtin_stpcpy (s, NULL); /* { dg-warning "null" "null pointer check" } */
36 __builtin_stpncpy (NULL, s, 16); /* { dg-warning "null" "null pointer check" } */
37 __builtin_stpncpy (s, NULL, 16); /* { dg-warning "null" "null pointer check" } */
38 __builtin_strcpy (NULL, s); /* { dg-warning "null" "null pointer check" } */
39 __builtin_strcpy (s, NULL); /* { dg-warning "null" "null pointer check" } */
40 __builtin_strncpy (NULL, s, 16); /* { dg-warning "null" "null pointer check" } */
41 __builtin_strncpy (s, NULL, 16); /* { dg-warning "null" "null pointer check" } */
42 __builtin_strcasecmp (NULL, s); /* { dg-warning "null" "null pointer check" } */
43 __builtin_strcasecmp (s, NULL); /* { dg-warning "null" "null pointer check" } */
44 __builtin_strncasecmp (NULL, s, 16); /* { dg-warning "null" "null pointer check" } */
45 __builtin_strncasecmp (s, NULL, 16); /* { dg-warning "null" "null pointer check" } */
46 __builtin_strcmp (NULL, s); /* { dg-warning "null" "null pointer check" } */
47 __builtin_strcmp (s, NULL); /* { dg-warning "null" "null pointer check" } */
48 __builtin_strncmp (NULL, s, 16); /* { dg-warning "null" "null pointer check" } */
49 __builtin_strncmp (s, NULL, 16); /* { dg-warning "null" "null pointer check" } */
50 __builtin_strlen (NULL); /* { dg-warning "null" "null pointer check" } */
51 __builtin_strstr (NULL, s); /* { dg-warning "null" "null pointer check" } */
52 __builtin_strstr (s, NULL); /* { dg-warning "null" "null pointer check" } */
53 __builtin_strpbrk (NULL, s); /* { dg-warning "null" "null pointer check" } */
54 __builtin_strpbrk (s, NULL); /* { dg-warning "null" "null pointer check" } */
55 __builtin_strspn (NULL, s); /* { dg-warning "null" "null pointer check" } */
56 __builtin_strspn (s, NULL); /* { dg-warning "null" "null pointer check" } */
57 __builtin_strchr (NULL, 16); /* { dg-warning "null" "null pointer check" } */
58 __builtin_strrchr (NULL, 16); /* { dg-warning "null" "null pointer check" } */
59 void *p1 = __builtin_strdup (NULL); /* { dg-warning "null" "null pointer check" } */
60 void *p2 = __builtin_strndup (NULL, 16); /* { dg-warning "null" "null pointer check" } */
62 __builtin_nan (NULL); /* { dg-warning "null" "null pointer check" } */
63 __builtin_nanf (NULL); /* { dg-warning "null" "null pointer check" } */
64 __builtin_nanl (NULL); /* { dg-warning "null" "null pointer check" } */
65 __builtin_nans (NULL); /* { dg-warning "null" "null pointer check" } */
66 __builtin_nansf (NULL); /* { dg-warning "null" "null pointer check" } */
67 __builtin_nansl (NULL); /* { dg-warning "null" "null pointer check" } */
69 __builtin_puts (NULL); /* { dg-warning "null" "null pointer check" } */
70 __builtin_fputc (*s, NULL); /* { dg-warning "null" "null pointer check" } */
71 __builtin_fputs (s, NULL); /* { dg-warning "null" "null pointer check" } */
72 __builtin_fputs (NULL, p); /* { dg-warning "null" "null pointer check" } */
73 __builtin_fwrite (s, 16, 16, NULL); /* { dg-warning "null" "null pointer check" } */
74 __builtin_fwrite (NULL, 16, 16, p); /* { dg-warning "null" "null pointer check" } */
75 __builtin_puts_unlocked (NULL); /* { dg-warning "null" "null pointer check" } */
76 __builtin_fputc_unlocked (*s, NULL); /* { dg-warning "null" "null pointer check" } */
77 __builtin_fputs_unlocked (s, NULL); /* { dg-warning "null" "null pointer check" } */
78 __builtin_fputs_unlocked (NULL, p); /* { dg-warning "null" "null pointer check" } */
79 __builtin_fwrite_unlocked (s, 16, 16, NULL); /* { dg-warning "null" "null pointer check" } */
80 __builtin_fwrite_unlocked (NULL, 16, 16, p); /* { dg-warning "null" "null pointer check" } */