unix-fns.c revision 99d9838b256ded8e59f85c93647ba5ec060b7145
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 4struct _opaque_pthread_once_t { 5 long __sig; 6 char __opaque[8]; 7}; 8typedef struct _opaque_pthread_once_t __darwin_pthread_once_t; 9typedef __darwin_pthread_once_t pthread_once_t; 10int pthread_once(pthread_once_t *, void (*)(void)); 11 12typedef void (^dispatch_block_t)(void); 13typedef long dispatch_once_t; 14void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block); 15 16#ifndef O_CREAT 17#define O_CREAT 0x0200 18#define O_RDONLY 0x0000 19#endif 20int open(const char *, int, ...); 21int close(int fildes); 22 23void 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} 33 34void 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} 38void 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 43void test_pthread_once_aux(); 44 45void 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} 49void test_pthread_once_neg() { 50 static pthread_once_t pred = {0x30B1BCBA, {0}}; 51 pthread_once(&pred, test_pthread_once_aux); // no-warning 52} 53