diff options
author | Anna Zaks <ganna@apple.com> | 2013-04-02 01:28:24 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2013-04-02 01:28:24 +0000 |
commit | 60bf5f45f799f77440b52deb3fe3ddec52e0ffa0 (patch) | |
tree | d196eb387a576769795809ff7e93161637cf0d78 /clang/test/Analysis/malloc.cpp | |
parent | 2832b4e8cb2da0a3d06646fb6b3d5d4a92b30364 (diff) | |
download | bcm5719-llvm-60bf5f45f799f77440b52deb3fe3ddec52e0ffa0.tar.gz bcm5719-llvm-60bf5f45f799f77440b52deb3fe3ddec52e0ffa0.zip |
[analyzer] Teach invalidateRegions that regions within LazyCompoundVal need to be invalidated
Refactor invalidateRegions to take SVals instead of Regions as input and teach RegionStore
about processing LazyCompoundVal as a top-level “escaping” value.
This addresses several false positives that get triggered by the NewDelete checker, but the
underlying issue is reproducible with other checkers as well (for example, MallocChecker).
llvm-svn: 178518
Diffstat (limited to 'clang/test/Analysis/malloc.cpp')
-rw-r--r-- | clang/test/Analysis/malloc.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/clang/test/Analysis/malloc.cpp b/clang/test/Analysis/malloc.cpp index a7c365289f3..54efa1c2bd7 100644 --- a/clang/test/Analysis/malloc.cpp +++ b/clang/test/Analysis/malloc.cpp @@ -5,7 +5,7 @@ void *malloc(size_t); void free(void *); void *realloc(void *ptr, size_t size); void *calloc(size_t nmemb, size_t size); - +char *strdup(const char *s); void checkThatMallocCheckerIsRunning() { malloc(4); @@ -67,3 +67,36 @@ struct X get() { result.a = malloc(4); return result; // no-warning } + +// Ensure that regions accessible through a LazyCompoundVal trigger region escape. +// Malloc checker used to report leaks for the following two test cases. +struct Property { + char* getterName; + Property(char* n) + : getterName(n) {} + +}; +void append(Property x); + +void appendWrapper(char *getterName) { + append(Property(getterName)); +} +void foo(const char* name) { + char* getterName = strdup(name); + appendWrapper(getterName); // no-warning +} + +struct NestedProperty { + Property prop; + NestedProperty(Property p) + : prop(p) {} +}; +void appendNested(NestedProperty x); + +void appendWrapperNested(char *getterName) { + appendNested(NestedProperty(Property(getterName))); +} +void fooNested(const char* name) { + char* getterName = strdup(name); + appendWrapperNested(getterName); // no-warning +}
\ No newline at end of file |