diff options
| author | Ted Kremenek <kremenek@apple.com> | 2010-04-08 19:53:31 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2010-04-08 19:53:31 +0000 |
| commit | ea4a5abf61b80c3020c63bf52d43cbb73b546af5 (patch) | |
| tree | 7dd8a38da6fb3c2f498dd01b1322594588f936b2 /clang/test | |
| parent | 7ffb294c5b1c778ef4287e356ade7633a909dbaf (diff) | |
| download | bcm5719-llvm-ea4a5abf61b80c3020c63bf52d43cbb73b546af5.tar.gz bcm5719-llvm-ea4a5abf61b80c3020c63bf52d43cbb73b546af5.zip | |
Add static analyzer check for calls to 'pthread_once()' where the control-flow has
automatic storage. This matches the corresponding check for 'dispatch_once()'.
llvm-svn: 100803
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Analysis/unix-fns.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/clang/test/Analysis/unix-fns.c b/clang/test/Analysis/unix-fns.c index 777ad197987..9d036ac7b5c 100644 --- a/clang/test/Analysis/unix-fns.c +++ b/clang/test/Analysis/unix-fns.c @@ -1,11 +1,24 @@ -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem %s -analyzer-store=region -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem %s -analyzer-store=basic +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem %s -analyzer-store=region -fblocks -verify +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem %s -analyzer-store=basic -fblocks -verify + +struct _opaque_pthread_once_t { + long __sig; + char __opaque[8]; +}; +typedef struct _opaque_pthread_once_t __darwin_pthread_once_t; +typedef __darwin_pthread_once_t pthread_once_t; +int pthread_once(pthread_once_t *, void (*)(void)); + +typedef void (^dispatch_block_t)(void); +typedef long dispatch_once_t; +void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block); #ifndef O_CREAT #define O_CREAT 0x0200 #define O_RDONLY 0x0000 #endif int open(const char *, int, ...); +int close(int fildes); void test_open(const char *path) { int fd; @@ -17,3 +30,23 @@ void test_open(const char *path) { if (!fd) close(fd); } + +void test_dispatch_once() { + dispatch_once_t pred = 0; + 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}} +} +void test_dispatch_once_neg() { + static dispatch_once_t pred = 0; + do { if (__builtin_expect(*(&pred), ~0l) != ~0l) dispatch_once((&pred), (^() {})); } while (0); // no-warning +} + +void test_pthread_once_aux(); + +void test_pthread_once() { + pthread_once_t pred = {0x30B1BCBA, {0}}; + pthread_once(&pred, test_pthread_once_aux); // expected-warning{{Call to 'pthread_once' uses the local variable 'pred' for the "control" value}} +} +void test_pthread_once_neg() { + static pthread_once_t pred = {0x30B1BCBA, {0}}; + pthread_once(&pred, test_pthread_once_aux); // no-warning +} |

