blob: 4d84c8b614a520ea1e97438975de669e212fd94e [file] [log] [blame]
Kristof Umann8fd74eb2019-01-26 20:06:54 +00001// RUN: %clang_analyze_cc1 -std=c++11 -verify %s \
2// RUN: -analyzer-checker=core \
3// RUN: -analyzer-checker=cplusplus.NewDelete \
4// RUN: -analyzer-checker=unix.MismatchedDeallocator
5//
6// RUN: %clang_analyze_cc1 -std=c++11 -verify %s \
7// RUN: -analyzer-checker=core \
8// RUN: -analyzer-checker=cplusplus.NewDelete \
9// RUN: -analyzer-checker=cplusplus.NewDeleteLeaks \
10// RUN: -analyzer-checker=unix.MismatchedDeallocator
11
Anton Yartseve3377fb2013-04-04 23:46:29 +000012// expected-no-diagnostics
13
14typedef __typeof(sizeof(int)) size_t;
15void *malloc(size_t);
16void free(void *);
17
18//------------------------------------------------------------------
19// Check that alpha.cplusplus.NewDelete + unix.MismatchedDeallocator
20// does not enable warnings produced by the unix.Malloc checker.
21//------------------------------------------------------------------
22void testMallocFreeNoWarn() {
23 int i;
24 free(&i); // no warn
25
26 int *p1 = (int *)malloc(sizeof(int));
27 free(++p1); // no warn
28
29 int *p2 = (int *)malloc(sizeof(int));
30 free(p2);
31 free(p2); // no warn
32
33 int *p3 = (int *)malloc(sizeof(int)); // no warn
34
35 int *p4 = (int *)malloc(sizeof(int));
36 free(p4);
37 int j = *p4; // no warn
38}