1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.deadcode.UnreachableCode,experimental.core.CastSize,unix.Malloc -analyzer-store=region -verify %s
2 
3 typedef __typeof(sizeof(int)) size_t;
4 void *malloc(size_t);
5 void free(void *);
6 void *realloc(void *ptr, size_t size);
7 void *calloc(size_t nmemb, size_t size);
8 
9 // Test for radar://11110132.
10 struct Foo {
11     mutable void* m_data;
12     Foo(void* data) : m_data(data) {}
13 };
14 Foo aFunction() {
15     return malloc(10);
16 }
17 
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.
22 int const_ptr_and_callback_def_param(int, const char*, int n, void(*)(void*) = 0);
23 void r11160612_3() {
24   char *x = (char*)malloc(12);
25   const_ptr_and_callback_def_param(0, x, 12);
26 }
27 
28 // Test member function pointer.
29 struct CanFreeMemory {
30   static void myFree(void*);
31 };
32 //This is handled because we look at the type of the parameter(not argument).
33 void r11160612_3(CanFreeMemory* p) {
34   char *x = (char*)malloc(12);
35   const_ptr_and_callback_def_param(0, x, 12, p->myFree);
36 }
37 
38