diff options
author | Artem Dergachev <artem.dergachev@gmail.com> | 2018-04-19 23:24:32 +0000 |
---|---|---|
committer | Artem Dergachev <artem.dergachev@gmail.com> | 2018-04-19 23:24:32 +0000 |
commit | 468bc0d8b9c5ca13af4c3d87b36dc544ccae9265 (patch) | |
tree | 68c990ba688dbc5a6a2f7ea0535c9584d9a77ac5 /clang/test/Analysis/malloc.mm | |
parent | b72daf00f45a92a07cd539025cf83f975ba65079 (diff) | |
download | bcm5719-llvm-468bc0d8b9c5ca13af4c3d87b36dc544ccae9265.tar.gz bcm5719-llvm-468bc0d8b9c5ca13af4c3d87b36dc544ccae9265.zip |
[analyzer] When we fail to evaluate a pointer cast, escape the pointer.
If a pointer cast fails (evaluates to an UnknownVal, i.e. not implemented in the
analyzer) and such cast is in fact the last use of the pointer, the pointer
symbol is no longer referenced by the program state and a leak is
(mis-)diagnosed.
"Escape" the pointer upon a failed cast, i.e. inform the checker that we can no
longer reliably track it.
Differential Revision: https://reviews.llvm.org/D45698
llvm-svn: 330380
Diffstat (limited to 'clang/test/Analysis/malloc.mm')
-rw-r--r-- | clang/test/Analysis/malloc.mm | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/test/Analysis/malloc.mm b/clang/test/Analysis/malloc.mm index e3daa858be8..d7bfbf3f34f 100644 --- a/clang/test/Analysis/malloc.mm +++ b/clang/test/Analysis/malloc.mm @@ -320,3 +320,13 @@ void test12365078_check_positive() { NSString *string = [[NSString alloc] initWithCharactersNoCopy:characters length:12 freeWhenDone:1]; if (string) free(characters); // expected-warning{{Attempt to free non-owned memory}} } + +void *test_reinterpret_cast_to_block() { + // Used to leak because the pointer was disappearing + // during the reinterpret_cast. + using BlockPtrTy = void (^)(); + struct Block {}; + Block* block = static_cast<Block*>(malloc(sizeof(Block))); + BlockPtrTy blockPtr = reinterpret_cast<BlockPtrTy>(block); // no-warning + return blockPtr; +} |