diff options
author | Jordan Rose <jordan_rose@apple.com> | 2013-05-01 23:10:44 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2013-05-01 23:10:44 +0000 |
commit | e2b1246a24e8babf2f58c93713fba16b8edb8e2d (patch) | |
tree | d8766203cedcf2cf15f3cdd862b207ebd89d374e /test/Analysis/malloc.cpp | |
parent | 776d3bb65c90278b9c65544b235d2ac40aea1d6e (diff) |
[analyzer] Consolidate constant evaluation logic in SValBuilder.
Previously, this was scattered across Environment (literal expressions),
ExprEngine (default arguments), and RegionStore (global constants). The
former special-cased several kinds of simple constant expressions, while
the latter two deferred to the AST's constant evaluator.
Now, these are all unified as SValBuilder::getConstantVal(). To keep
Environment fast, the special cases for simple constant expressions have
been left in, but the main benefits are that (a) unusual constants like
ObjCStringLiterals now work as default arguments and global constant
initializers, and (b) we're not duplicating code between ExprEngine and
RegionStore.
This actually caught a bug in our test suite, which is awesome: we stop
tracking allocated memory if it's passed as an argument along with some
kind of callback, but not if the callback is 0. We were testing this in
a case where the callback parameter had a default value, but that value
was 0. After this change, the analyzer now (correctly) flags that as a
leak!
<rdar://problem/13773117>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180894 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis/malloc.cpp')
-rw-r--r-- | test/Analysis/malloc.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/test/Analysis/malloc.cpp b/test/Analysis/malloc.cpp index 54efa1c2bd..75d06d66c2 100644 --- a/test/Analysis/malloc.cpp +++ b/test/Analysis/malloc.cpp @@ -24,12 +24,18 @@ Foo aFunction() { // they are defined in system headers and take the const pointer to the // allocated memory. (radar://11160612) // Test default parameter. -int const_ptr_and_callback_def_param(int, const char*, int n, void(*)(void*) = 0); +int const_ptr_and_callback_def_param(int, const char*, int n, void(*)(void*) = free); void r11160612_3() { char *x = (char*)malloc(12); const_ptr_and_callback_def_param(0, x, 12); } +int const_ptr_and_callback_def_param_null(int, const char*, int n, void(*)(void*) = 0); +void r11160612_no_callback() { + char *x = (char*)malloc(12); + const_ptr_and_callback_def_param_null(0, x, 12); +} // expected-warning{{leak}} + // Test member function pointer. struct CanFreeMemory { static void myFree(void*); |