summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/malloc.c
diff options
context:
space:
mode:
authorArtem Dergachev <artem.dergachev@gmail.com>2016-04-25 14:44:25 +0000
committerArtem Dergachev <artem.dergachev@gmail.com>2016-04-25 14:44:25 +0000
commit70247e69b1f1fde7f11b6cd81bc50162f9b79ab2 (patch)
treec562c6bc4b43624c42b4ecbb8c562048ec2ffa52 /clang/test/Analysis/malloc.c
parentdd215236530c9f643220f1c6e928dd39254a7b3d (diff)
downloadbcm5719-llvm-70247e69b1f1fde7f11b6cd81bc50162f9b79ab2.tar.gz
bcm5719-llvm-70247e69b1f1fde7f11b6cd81bc50162f9b79ab2.zip
[analyzer] Let TK_PreserveContents span across the whole base region.
If an address of a field is passed through a const pointer, the whole structure's base region should receive the TK_PreserveContents trait and avoid invalidation. Additionally, include a few FIXME tests shown up during testing. Differential Revision: http://reviews.llvm.org/D19057 llvm-svn: 267413
Diffstat (limited to 'clang/test/Analysis/malloc.c')
-rw-r--r--clang/test/Analysis/malloc.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c
index 30d72691956..51e2cd60432 100644
--- a/clang/test/Analysis/malloc.c
+++ b/clang/test/Analysis/malloc.c
@@ -1750,6 +1750,19 @@ void testEscapeThroughSystemCallTakingVoidPointer3(fake_rb_tree_t *rbt) {
fake_rb_tree_insert_node(rbt, data); // no warning
}
+struct IntAndPtr {
+ int x;
+ int *p;
+};
+
+void constEscape(const void *ptr);
+
+void testConstEscapeThroughAnotherField() {
+ struct IntAndPtr s;
+ s.p = malloc(sizeof(int));
+ constEscape(&(s.x)); // could free s->p!
+} // no-warning
+
// ----------------------------------------------------------------------------
// False negatives.
@@ -1769,3 +1782,9 @@ void testPassToSystemHeaderFunctionIndirectly() {
// FIXME: This is a leak: if we think a system function won't free p, it
// won't free (p-1) either.
}
+
+void testMallocIntoMalloc() {
+ StructWithPtr *s = malloc(sizeof(StructWithPtr));
+ s->memP = malloc(sizeof(int));
+ free(s);
+} // FIXME: should warn here
OpenPOWER on IntegriCloud