aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/nonnull.m
blob: 0cea80b536d801977415ecffc6cc275ee4d5e87f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// RUN: %clang_cc1 -analyze -analyzer-checker=core -w -verify %s

@interface MyObject
- (void)takePointer:(void *)ptr __attribute__((nonnull(1)));
- (void)takePointerArg:(void *)__attribute__((nonnull)) ptr;

@end

void testNonNullMethod(int *p, MyObject *obj) {
  if (p)
    return;
  [obj takePointer:p]; // expected-warning{{nonnull}}
}


@interface Subclass : MyObject
// [[nonnull]] is an inherited attribute.
- (void)takePointer:(void *)ptr;
@end

void testSubclass(int *p, Subclass *obj) {
  if (p)
    return;
  [obj takePointer:p]; // expected-warning{{nonnull}}
}

void testSubclassArg(int *p, Subclass *obj) {
  if (p)
    return;
  [obj takePointerArg:p]; // expected-warning{{nonnull}}
}


union rdar16153464_const_cp_t {
  const struct rdar16153464_cczp *zp;
  const struct rdar16153464_cczp_prime *prime;
} __attribute__((transparent_union));

struct rdar16153464_header {
  union rdar16153464_const_cp_t cp;
  unsigned char pad[16 - sizeof(union rdar16153464_const_cp_t *)];
} __attribute__((aligned(16)));


struct rdar16153464_full_ctx {
  struct rdar16153464_header hdr;
} __attribute__((aligned(16)));


struct rdar16153464_pub_ctx {
  struct rdar16153464_header hdr;
} __attribute__((aligned(16)));


union rdar16153464_full_ctx_t {
  struct rdar16153464_full_ctx *_full;
  struct rdar16153464_header *hdr;
  struct rdar16153464_body *body;
  struct rdar16153464_public *pub;
} __attribute__((transparent_union));

union rdar16153464_pub_ctx_t {
  struct rdar16153464_pub_ctx *_pub;
  struct rdar16153464_full_ctx *_full;
  struct rdar16153464_header *hdr;
  struct rdar16153464_body *body;
  struct rdar16153464_public *pub;
  union rdar16153464_full_ctx_t innert;
} __attribute__((transparent_union));

int rdar16153464(union rdar16153464_full_ctx_t inner)
{
  extern void rdar16153464_check(union rdar16153464_pub_ctx_t outer) __attribute((nonnull(1)));
  rdar16153464_check((union rdar16153464_pub_ctx_t){ .innert = inner }); // no-warning
  rdar16153464_check(inner); // no-warning
  rdar16153464_check(0); // expected-warning{{nonnull}}
}