blob: 72b92722133bd3948387e883dc8f8496e907b416 [file] [log] [blame]
Anna Zaks4b81e742012-03-29 23:26:54 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.deadcode.UnreachableCode,experimental.core.CastSize,unix.Malloc -analyzer-store=region -verify %s
2
3typedef __typeof(sizeof(int)) size_t;
4void *malloc(size_t);
5void free(void *);
6void *realloc(void *ptr, size_t size);
7void *calloc(size_t nmemb, size_t size);
8
9// Test for radar://11110132.
10struct Foo {
11 mutable void* m_data;
12 Foo(void* data) : m_data(data) {}
13};
14Foo aFunction() {
15 return malloc(10);
16}
Anna Zaksaca0ac52012-05-03 23:50:28 +000017
18// Assume that functions which take a function pointer can free memory even if
19// they are defined in system headers and take the const pointer to the
20// allocated memory. (radar://11160612)
21// Test default parameter.
22int const_ptr_and_callback_def_param(int, const char*, int n, void(*)(void*) = 0);
23void r11160612_3() {
24 char *x = (char*)malloc(12);
25 const_ptr_and_callback_def_param(0, x, 12);
26}
Anna Zaksf132ba82012-05-04 22:18:36 +000027
28// Test member function pointer.
29struct CanFreeMemory {
30 static void myFree(void*);
31};
32//This is handled because we look at the type of the parameter(not argument).
33void r11160612_3(CanFreeMemory* p) {
34 char *x = (char*)malloc(12);
35 const_ptr_and_callback_def_param(0, x, 12, p->myFree);
36}
37