39 lines · cpp
1// 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.MismatchedDeallocator5//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.MismatchedDeallocator11 12// expected-no-diagnostics13 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 warn25 26 int *p1 = (int *)malloc(sizeof(int));27 free(++p1); // no warn28 29 int *p2 = (int *)malloc(sizeof(int));30 free(p2);31 free(p2); // no warn32 33 int *p3 = (int *)malloc(sizeof(int)); // no warn34 35 int *p4 = (int *)malloc(sizeof(int));36 free(p4);37 int j = *p4; // no warn38}39