[PATCH] D21506: [analyzer] Block in critical section
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 20 03:45:19 PDT 2016
NoQ added a comment.
Useful stuff!
When I see your approach with `mutexCount`, the following test case comes to mind:
std::mutex m;
void foo() {
// Suppose this function is always called
// with the mutex 'm' locked.
m.unlock();
// Here probably some useful work is done.
m.lock();
// What's the current mutex count?
sleep(1); // expected-warning{{}}
}
================
Comment at: lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp:11
@@ +10,3 @@
+// Defines a checker for blocks in critical sections. This checker should find
+// the calls to blocking functions (for example: sleep, getc, fgets, read,
+// recv etc.) inside a critical section. When sleep(x) is called while a mutex
----------------
A bit of trailing whitespace here.
================
Comment at: test/Analysis/block-in-critical-section.cpp:1
@@ +1,2 @@
+// RUN: %clang --analyze -std=c++11 -Xclang -analyzer-checker -Xclang alpha.unix.BlockInCriticalSection %s
+
----------------
The run line is lacking `-verify`, and therefore these tests always pass. In your case, it'd be `-Xclang -verify`. On the other hand, i'm not sure if it's a good idea to run the test under the driver, instead of the standard `-cc1` approach - after all, you aren't including any system headers in the test.
Repository:
rL LLVM
http://reviews.llvm.org/D21506
More information about the cfe-commits
mailing list