summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/MismatchedDeallocator-checker-test.mm
diff options
context:
space:
mode:
authorIsmail Pazarbasi <ismail.pazarbasi@gmail.com>2015-05-18 19:59:11 +0000
committerIsmail Pazarbasi <ismail.pazarbasi@gmail.com>2015-05-18 19:59:11 +0000
commite5768d1717a354531f00062fdaf5d1dfbbedf12b (patch)
tree22c0dc5782308e6e284428b877eff0e386fb3f6a /clang/test/Analysis/MismatchedDeallocator-checker-test.mm
parent1d4911bc994789169594be634ae158966fc41cfb (diff)
downloadbcm5719-llvm-e5768d1717a354531f00062fdaf5d1dfbbedf12b.tar.gz
bcm5719-llvm-e5768d1717a354531f00062fdaf5d1dfbbedf12b.zip
Detect uses of mismatching forms of 'new' and 'delete'
Emit warning when operand to `delete` is allocated with `new[]` or operand to `delete[]` is allocated with `new`. rev 2 update: `getNewExprFromInitListOrExpr` should return `dyn_cast_or_null` instead of `dyn_cast`, since `E` might be null. Reviewers: rtrieu, jordan_rose, rsmith Subscribers: majnemer, cfe-commits Differential Revision: http://reviews.llvm.org/D4661 llvm-svn: 237608
Diffstat (limited to 'clang/test/Analysis/MismatchedDeallocator-checker-test.mm')
-rw-r--r--clang/test/Analysis/MismatchedDeallocator-checker-test.mm11
1 files changed, 9 insertions, 2 deletions
diff --git a/clang/test/Analysis/MismatchedDeallocator-checker-test.mm b/clang/test/Analysis/MismatchedDeallocator-checker-test.mm
index 15815e80bfa..3cc3e18c7c7 100644
--- a/clang/test/Analysis/MismatchedDeallocator-checker-test.mm
+++ b/clang/test/Analysis/MismatchedDeallocator-checker-test.mm
@@ -95,8 +95,11 @@ void testNew6() {
realloc(p, sizeof(long)); // expected-warning{{Memory allocated by 'new[]' should be deallocated by 'delete[]', not realloc()}}
}
+int *allocInt() {
+ return new int;
+}
void testNew7() {
- int *p = new int;
+ int *p = allocInt();
delete[] p; // expected-warning{{Memory allocated by 'new' should be deallocated by 'delete', not 'delete[]'}}
}
@@ -105,8 +108,12 @@ void testNew8() {
delete[] p; // expected-warning{{Memory allocated by operator new should be deallocated by 'delete', not 'delete[]'}}
}
+int *allocIntArray(unsigned c) {
+ return new int[c];
+}
+
void testNew9() {
- int *p = new int[1];
+ int *p = allocIntArray(1);
delete p; // expected-warning{{Memory allocated by 'new[]' should be deallocated by 'delete[]', not 'delete'}}
}
OpenPOWER on IntegriCloud