Ted Kremenek | 99d9838 | 2010-04-08 19:53:31 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem %s -analyzer-store=region -fblocks -verify |
| 2 | // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem %s -analyzer-store=basic -fblocks -verify |
| 3 | |
| 4 | struct _opaque_pthread_once_t { |
| 5 | long __sig; |
| 6 | char __opaque[8]; |
| 7 | }; |
| 8 | typedef struct _opaque_pthread_once_t __darwin_pthread_once_t; |
| 9 | typedef __darwin_pthread_once_t pthread_once_t; |
| 10 | int pthread_once(pthread_once_t *, void (*)(void)); |
| 11 | |
| 12 | typedef void (^dispatch_block_t)(void); |
| 13 | typedef long dispatch_once_t; |
| 14 | void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block); |
Ted Kremenek | 381d1bf | 2010-02-25 00:20:35 +0000 | [diff] [blame] | 15 | |
Ted Kremenek | fc89323 | 2010-02-25 01:16:07 +0000 | [diff] [blame] | 16 | #ifndef O_CREAT |
| 17 | #define O_CREAT 0x0200 |
| 18 | #define O_RDONLY 0x0000 |
| 19 | #endif |
| 20 | int open(const char *, int, ...); |
Ted Kremenek | 99d9838 | 2010-04-08 19:53:31 +0000 | [diff] [blame] | 21 | int close(int fildes); |
Ted Kremenek | 381d1bf | 2010-02-25 00:20:35 +0000 | [diff] [blame] | 22 | |
| 23 | void test_open(const char *path) { |
| 24 | int fd; |
| 25 | fd = open(path, O_RDONLY); // no-warning |
| 26 | if (!fd) |
| 27 | close(fd); |
| 28 | |
| 29 | fd = open(path, O_CREAT); // expected-warning{{Call to 'open' requires a third argument when the 'O_CREAT' flag is set}} |
| 30 | if (!fd) |
| 31 | close(fd); |
| 32 | } |
Ted Kremenek | 99d9838 | 2010-04-08 19:53:31 +0000 | [diff] [blame] | 33 | |
| 34 | void test_dispatch_once() { |
| 35 | dispatch_once_t pred = 0; |
| 36 | do { if (__builtin_expect(*(&pred), ~0l) != ~0l) dispatch_once((&pred), (^() {})); } while (0); // expected-warning{{Call to 'dispatch_once' uses the local variable 'pred' for the predicate value}} |
| 37 | } |
| 38 | void test_dispatch_once_neg() { |
| 39 | static dispatch_once_t pred = 0; |
| 40 | do { if (__builtin_expect(*(&pred), ~0l) != ~0l) dispatch_once((&pred), (^() {})); } while (0); // no-warning |
| 41 | } |
| 42 | |
| 43 | void test_pthread_once_aux(); |
| 44 | |
| 45 | void test_pthread_once() { |
| 46 | pthread_once_t pred = {0x30B1BCBA, {0}}; |
| 47 | pthread_once(&pred, test_pthread_once_aux); // expected-warning{{Call to 'pthread_once' uses the local variable 'pred' for the "control" value}} |
| 48 | } |
| 49 | void test_pthread_once_neg() { |
| 50 | static pthread_once_t pred = {0x30B1BCBA, {0}}; |
| 51 | pthread_once(&pred, test_pthread_once_aux); // no-warning |
| 52 | } |