From 39fcc9a984e2820e4ea0fa2ac4abd17d9f3a31df Mon Sep 17 00:00:00 2001 From: dim Date: Sun, 20 Feb 2011 13:06:31 +0000 Subject: Vendor import of clang trunk r126079: http://llvm.org/svn/llvm-project/cfe/trunk@126079 --- test/Analysis/unix-fns.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'test/Analysis/unix-fns.c') diff --git a/test/Analysis/unix-fns.c b/test/Analysis/unix-fns.c index 9d036ac..9f5362d 100644 --- a/test/Analysis/unix-fns.c +++ b/test/Analysis/unix-fns.c @@ -1,5 +1,5 @@ -// 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 +// 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 +// 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 struct _opaque_pthread_once_t { long __sig; @@ -8,6 +8,9 @@ struct _opaque_pthread_once_t { 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 long unsigned int __darwin_size_t; +typedef __darwin_size_t size_t; +void *malloc(size_t); typedef void (^dispatch_block_t)(void); typedef long dispatch_once_t; @@ -50,3 +53,17 @@ void test_pthread_once_neg() { static pthread_once_t pred = {0x30B1BCBA, {0}}; pthread_once(&pred, test_pthread_once_aux); // no-warning } + +// PR 2899 - warn of zero-sized allocations to malloc(). +void pr2899() { + char* foo = malloc(0); // expected-warning{{Call to 'malloc' has an allocation size of 0 bytes}} + for (unsigned i = 0; i < 100; i++) { + foo[i] = 0; + } +} +void pr2899_nowarn(size_t size) { + char* foo = malloc(size); // no-warning + for (unsigned i = 0; i < 100; i++) { + foo[i] = 0; + } +} -- cgit v1.1