Home | History | Annotate | Download | only in Analysis
      1 // RUN: %clang_cc1 -analyze -analyzer-checker=core -w -verify %s
      2 
      3 @interface MyObject
      4 - (void)takePointer:(void *)ptr __attribute__((nonnull(1)));
      5 - (void)takePointerArg:(void *)__attribute__((nonnull)) ptr;
      6 
      7 @end
      8 
      9 void testNonNullMethod(int *p, MyObject *obj) {
     10   if (p)
     11     return;
     12   [obj takePointer:p]; // expected-warning{{nonnull}}
     13 }
     14 
     15 
     16 @interface Subclass : MyObject
     17 // [[nonnull]] is an inherited attribute.
     18 - (void)takePointer:(void *)ptr;
     19 @end
     20 
     21 void testSubclass(int *p, Subclass *obj) {
     22   if (p)
     23     return;
     24   [obj takePointer:p]; // expected-warning{{nonnull}}
     25 }
     26 
     27 void testSubclassArg(int *p, Subclass *obj) {
     28   if (p)
     29     return;
     30   [obj takePointerArg:p]; // expected-warning{{nonnull}}
     31 }
     32 
     33 
     34 union rdar16153464_const_cp_t {
     35   const struct rdar16153464_cczp *zp;
     36   const struct rdar16153464_cczp_prime *prime;
     37 } __attribute__((transparent_union));
     38 
     39 struct rdar16153464_header {
     40   union rdar16153464_const_cp_t cp;
     41   unsigned char pad[16 - sizeof(union rdar16153464_const_cp_t *)];
     42 } __attribute__((aligned(16)));
     43 
     44 
     45 struct rdar16153464_full_ctx {
     46   struct rdar16153464_header hdr;
     47 } __attribute__((aligned(16)));
     48 
     49 
     50 struct rdar16153464_pub_ctx {
     51   struct rdar16153464_header hdr;
     52 } __attribute__((aligned(16)));
     53 
     54 
     55 union rdar16153464_full_ctx_t {
     56   struct rdar16153464_full_ctx *_full;
     57   struct rdar16153464_header *hdr;
     58   struct rdar16153464_body *body;
     59   struct rdar16153464_public *pub;
     60 } __attribute__((transparent_union));
     61 
     62 union rdar16153464_pub_ctx_t {
     63   struct rdar16153464_pub_ctx *_pub;
     64   struct rdar16153464_full_ctx *_full;
     65   struct rdar16153464_header *hdr;
     66   struct rdar16153464_body *body;
     67   struct rdar16153464_public *pub;
     68   union rdar16153464_full_ctx_t innert;
     69 } __attribute__((transparent_union));
     70 
     71 int rdar16153464(union rdar16153464_full_ctx_t inner)
     72 {
     73   extern void rdar16153464_check(union rdar16153464_pub_ctx_t outer) __attribute((nonnull(1)));
     74   rdar16153464_check((union rdar16153464_pub_ctx_t){ .innert = inner }); // no-warning
     75   rdar16153464_check(inner); // no-warning
     76   rdar16153464_check(0); // expected-warning{{nonnull}}
     77 }
     78