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 | |
| 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')
| -rw-r--r-- | clang/test/Analysis/malloc.mm | 10 | ||||
| -rw-r--r-- | clang/test/Analysis/pr22954.c | 5 |
2 files changed, 13 insertions, 2 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; +} diff --git a/clang/test/Analysis/pr22954.c b/clang/test/Analysis/pr22954.c index 64a00c5ec08..b4273c0a894 100644 --- a/clang/test/Analysis/pr22954.c +++ b/clang/test/Analysis/pr22954.c @@ -624,9 +624,10 @@ int f29(int i, int j, int k, int l, int m) { clang_analyzer_eval(m29[i].s3[1] == 1); // expected-warning{{UNKNOWN}} clang_analyzer_eval(m29[i].s3[2] == 1); // expected-warning{{UNKNOWN}} clang_analyzer_eval(m29[i].s3[3] == 1); // expected-warning{{UNKNOWN}} - clang_analyzer_eval(m29[j].s3[k] == 1); // expected-warning{{TRUE}}\ - expected-warning{{Potential leak of memory pointed to by field 's4'}} + clang_analyzer_eval(m29[j].s3[k] == 1); // expected-warning{{TRUE}} clang_analyzer_eval(l29->s1[m] == 2); // expected-warning{{UNKNOWN}} + // FIXME: Should warn that m29[i].s4 leaks. But not on the previous line, + // because l29 and m29 alias. return 0; } |

