malloc.cpp revision aca0ac58d2ae80d764e3832456667d7322445e0c
1// 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}
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.
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}
27