]> granicus.if.org Git - clang/commit
[analyzer] Add a checker that detects blocks in critical sections
authorAnna Zaks <ganna@apple.com>
Tue, 20 Sep 2016 20:28:50 +0000 (20:28 +0000)
committerAnna Zaks <ganna@apple.com>
Tue, 20 Sep 2016 20:28:50 +0000 (20:28 +0000)
commitd9e26cad3c65d67e8fd1cb73e5bd09e268cd870f
tree6d3915f8d3a300002c86c529e6fa7dce7ef6def0
parent1be4cc56c26945b7e14a361117e2b426e47aede9
[analyzer] Add a checker that detects 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 is held, other threads cannot lock the same mutex. This might take some time, leading to bad performance or even deadlock.

Example:

mutex_t m;

void f() {
  sleep(1000); // Error: sleep() while m is locked! [f() is called from foobar() while m is locked]
  // do some work
}

void foobar() {
  lock(m);
  f();
  unlock(m);
}

A patch by zdtorok (Zoltán Dániel Török)!

Differential Revision: https://reviews.llvm.org/D21506

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282011 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/StaticAnalyzer/Checkers/Checkers.td
lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp [new file with mode: 0644]
lib/StaticAnalyzer/Checkers/CMakeLists.txt
test/Analysis/block-in-critical-section.cpp [new file with mode: 0644]