[Heikki Kultala] This patch contains the ABI changes for the TCE target.
[clang.git] / test / Analysis / unix-fns.c
blob9f5362d184ff00dc48ced61267787973bd84ecfc
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 {
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 typedef long unsigned int __darwin_size_t;
12 typedef __darwin_size_t size_t;
13 void *malloc(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);
19 #ifndef O_CREAT
20 #define O_CREAT 0x0200
21 #define O_RDONLY 0x0000
22 #endif
23 int open(const char *, int, ...);
24 int close(int fildes);
26 void test_open(const char *path) {
27 int fd;
28 fd = open(path, O_RDONLY); // no-warning
29 if (!fd)
30 close(fd);
32 fd = open(path, O_CREAT); // expected-warning{{Call to 'open' requires a third argument when the 'O_CREAT' flag is set}}
33 if (!fd)
34 close(fd);
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().
58 void pr2899() {
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++) {
61 foo[i] = 0;
64 void pr2899_nowarn(size_t size) {
65 char* foo = malloc(size); // no-warning
66 for (unsigned i = 0; i < 100; i++) {
67 foo[i] = 0;