annotate gcc/testsuite/gcc.dg/nonnull-1.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Test for the "nonnull" function attribute. */
kono
parents:
diff changeset
2 /* Origin: Jason Thorpe <thorpej@wasabisystems.com> */
kono
parents:
diff changeset
3 /* { dg-do compile } */
kono
parents:
diff changeset
4 /* { dg-options "-Wnonnull" } */
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 #include <stddef.h>
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 extern void func1 (char *, char *, int) __attribute__((nonnull));
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 extern void func2 (char *, char *) __attribute__((nonnull(1)));
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 extern void func3 (char *, int, char *, int)
kono
parents:
diff changeset
13 __attribute__((nonnull(1,3)));
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 extern void func4 (char *, char *) __attribute__((nonnull(1)))
kono
parents:
diff changeset
16 __attribute__((nonnull(2)));
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 void
kono
parents:
diff changeset
19 foo (int i1, int i2, int i3, char *cp1, char *cp2, char *cp3)
kono
parents:
diff changeset
20 {
kono
parents:
diff changeset
21 func1(cp1, cp2, i1);
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 func1(NULL, cp2, i1); /* { dg-warning "null" "null with argless nonnull 1" } */
kono
parents:
diff changeset
24 func1(cp1, NULL, i1); /* { dg-warning "null" "null with argless nonnull 2" } */
kono
parents:
diff changeset
25 func1(cp1, cp2, 0);
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 func2(cp1, NULL);
kono
parents:
diff changeset
28 func2(NULL, cp1); /* { dg-warning "null" "null with single explicit nonnull" } */
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 func3(NULL, i2, cp3, i3); /* { dg-warning "null" "null with explicit nonnull 1" } */
kono
parents:
diff changeset
31 func3(cp3, i2, NULL, i3); /* { dg-warning "null" "null with explicit nonnull 3" } */
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 func1(i1 ? cp1 : NULL, cp2, i3); /* { dg-warning "null" "null with cond expr rhs" } */
kono
parents:
diff changeset
34 func1(i1 ? NULL : cp1, cp2, i3); /* { dg-warning "null" "null with cond expr lhs" } */
kono
parents:
diff changeset
35 func1(i1 ? (i2 ? cp1 : NULL) : cp2, cp3, i3); /* { dg-warning "null" "null with nested cond expr" } */
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 func4(NULL, cp1); /* { dg-warning "null" "null with multiple attributes 1" } */
kono
parents:
diff changeset
38 func4(cp1, NULL); /* { dg-warning "null" "null with multiple attributes 2" } */
kono
parents:
diff changeset
39 }