This patch adds a small utility to match function calls and Obj-C messages. This utility abstracts away the mutable keywords and the lazy initialization and caching logic of identifiers from the checkers. The SimpleStreamChecker is ported over this utility within this patch to show the reduction of code and to test this change.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h | ||
---|---|---|
309 ↗ | (On Diff #44110) | "is call" -> "is a call" |
lib/StaticAnalyzer/Core/CheckerContext.cpp | ||
41 ↗ | (On Diff #44110) | Please, add && "ObjC Methods are not supported" |
47 ↗ | (On Diff #44110) | You can micro optimize by checking if the identifier matches first (and only checking arguments later); in most cases it won't. |
57 ↗ | (On Diff #44110) | This will only match against the first part of the ObjC method name. Also, this is not tested. I am Ok with adding the ObjC support later and adding an assert above to error out if this is used for ObjC. |
- Removed support for matching ObjC messages. It might be added in a later.
- Addressed review comments.
include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h | ||
---|---|---|
312 ↗ | (On Diff #44325) | The API is a bit awkward. Maybe it would be better if we make this a member of CallEvent as you've suggested initially? |
include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h | ||
---|---|---|
312 ↗ | (On Diff #44325) | I agree. Moved it to CallEvent. |
FYI: this revision has likely broken the build: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/9561
FAIL: Clang :: Analysis/simple-stream-checks.c (367 of 8927) ******************** TEST 'Clang :: Analysis/simple-stream-checks.c' FAILED ******************** Script: -- /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_asan/./bin/clang -cc1 -internal-isystem /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/../lib/clang/3.9.0/include -nostdsysteminc -analyze -analyzer-checker=core,alpha.unix.SimpleStream -verify /mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/test/Analysis/simple-stream-checks.c --
Thank you for the fix and sorry for not noticing this. I was unlucky and the tests did pass on my machine.
Side note: Has anybody ever considered just treating fopen and fclose like malloc and free?
On Windows I use a trick that I discovered what I call "the _Post_ptr_invalid_ hack" because* the _Post_ptr_invalid_ SAL annotation lets me treat the argument to CloseHandle like the argument to free, and reports double closes as double frees.
Here we'd just treat the FILE* as a different region of memory, to check that they're not mixed.
- this also works in part because a Windows HANDLE is just a typedefd void*
cfe/trunk/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp | ||
---|---|---|
106 | Why specify the RequiredArgs for fclose, and not fopen? |
Side note: Has anybody ever considered just treating fopen and fclose like malloc and free?
Yes, there are a few checkers that follow the same open/close rule and could in theory be merged together.
cfe/trunk/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp | ||
---|---|---|
106 | Not sure. Maybe it's an omission. |
Why specify the RequiredArgs for fclose, and not fopen?