1 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem -analyzer-checker=unix.API -analyzer-checker=macosx.API %s -analyzer-store=region -fblocks -verify
2 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-check-objc-mem -analyzer-checker=unix.API -analyzer-checker=macosx.API %s -analyzer-store=basic -fblocks -verify
4 struct _opaque_pthread_once_t
{
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 typedef long unsigned int __darwin_size_t
;
12 typedef __darwin_size_t
size_t;
15 typedef void (^dispatch_block_t
)(void);
16 typedef long dispatch_once_t
;
17 void dispatch_once(dispatch_once_t
*predicate
, dispatch_block_t block
);
20 #define O_CREAT 0x0200
21 #define O_RDONLY 0x0000
23 int open(const char *, int, ...);
24 int close(int fildes
);
26 void test_open(const char *path
) {
28 fd
= open(path
, O_RDONLY
); // no-warning
32 fd
= open(path
, O_CREAT
); // expected-warning{{Call to 'open' requires a third argument when the 'O_CREAT' flag is set}}
37 void test_dispatch_once() {
38 dispatch_once_t pred
= 0;
39 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}}
41 void test_dispatch_once_neg() {
42 static dispatch_once_t pred
= 0;
43 do { if (__builtin_expect(*(&pred
), ~0l) != ~0l) dispatch_once((&pred
), (^() {})); } while (0); // no-warning
46 void test_pthread_once_aux();
48 void test_pthread_once() {
49 pthread_once_t pred
= {0x30B1BCBA, {0}};
50 pthread_once(&pred
, test_pthread_once_aux
); // expected-warning{{Call to 'pthread_once' uses the local variable 'pred' for the "control" value}}
52 void test_pthread_once_neg() {
53 static pthread_once_t pred
= {0x30B1BCBA, {0}};
54 pthread_once(&pred
, test_pthread_once_aux
); // no-warning
57 // PR 2899 - warn of zero-sized allocations to malloc().
59 char* foo
= malloc(0); // expected-warning{{Call to 'malloc' has an allocation size of 0 bytes}}
60 for (unsigned i
= 0; i
< 100; i
++) {
64 void pr2899_nowarn(size_t size
) {
65 char* foo
= malloc(size
); // no-warning
66 for (unsigned i
= 0; i
< 100; i
++) {