diff options
Diffstat (limited to 'test/Analysis/malloc.c')
-rw-r--r-- | test/Analysis/malloc.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/Analysis/malloc.c b/test/Analysis/malloc.c index 8e0f5c04ca..5288e21a28 100644 --- a/test/Analysis/malloc.c +++ b/test/Analysis/malloc.c @@ -1794,6 +1794,40 @@ void testNoCrashOnOffendingParameter() { allocateSomeMemory(offendingParameter, &ptr); } // expected-warning {{Potential leak of memory pointed to by 'ptr'}} + +// Test a false positive caused by a bug in liveness analysis. +struct A { + int *buf; +}; +struct B { + struct A *a; +}; +void livenessBugRealloc(struct A *a) { + a->buf = realloc(a->buf, sizeof(int)); // no-warning +} +void testLivenessBug(struct B *in_b) { + struct B *b = in_b; + livenessBugRealloc(b->a); + ((void) 0); // An attempt to trick liveness analysis. + livenessBugRealloc(b->a); +} + +struct ListInfo { + struct ListInfo *next; +}; + +struct ConcreteListItem { + struct ListInfo li; + int i; +}; + +void list_add(struct ListInfo *list, struct ListInfo *item); + +void testCStyleListItems(struct ListInfo *list) { + struct ConcreteListItem *x = malloc(sizeof(struct ConcreteListItem)); + list_add(list, &x->li); // will free 'x'. +} + // ---------------------------------------------------------------------------- // False negatives. |