summaryrefslogtreecommitdiff
path: root/test/Analysis
diff options
context:
space:
mode:
authorGabor Horvath <xazax.hun@gmail.com>2017-10-30 10:09:55 +0000
committerGabor Horvath <xazax.hun@gmail.com>2017-10-30 10:09:55 +0000
commita621a8df84caef38f942e31b2a3a6e2fbadf1732 (patch)
tree39fd1871e18fe06419b966a1606945ffa6df57fe /test/Analysis
parent402bbf7dc2644b64a530dc77fd120b0fd9a6a45b (diff)
[analyzer] lock_guard and unique_lock extension for BlockInCriticalSection checker
A patch by zdtorok (Zoltán Dániel Török)! Differential Revision: https://reviews.llvm.org/D33729 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316892 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Analysis')
-rw-r--r--test/Analysis/block-in-critical-section.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/Analysis/block-in-critical-section.cpp b/test/Analysis/block-in-critical-section.cpp
index c65cc612cf..fcf6188fc0 100644
--- a/test/Analysis/block-in-critical-section.cpp
+++ b/test/Analysis/block-in-critical-section.cpp
@@ -7,6 +7,20 @@ struct mutex {
void lock() {}
void unlock() {}
};
+template<typename T>
+struct lock_guard {
+ lock_guard<T>(std::mutex) {}
+ ~lock_guard<T>() {}
+};
+template<typename T>
+struct unique_lock {
+ unique_lock<T>(std::mutex) {}
+ ~unique_lock<T>() {}
+};
+template<typename T>
+struct not_real_lock {
+ not_real_lock<T>(std::mutex) {}
+};
}
void getc() {}
@@ -110,3 +124,31 @@ void testBlockInCriticalSectionUnexpectedUnlock() {
m.lock();
sleep(1); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
}
+
+void testBlockInCriticalSectionLockGuard() {
+ std::mutex g_mutex;
+ std::not_real_lock<std::mutex> not_real_lock(g_mutex);
+ sleep(1); // no-warning
+
+ std::lock_guard<std::mutex> lock(g_mutex);
+ sleep(1); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
+}
+
+void testBlockInCriticalSectionLockGuardNested() {
+ testBlockInCriticalSectionLockGuard();
+ sleep(1); // no-warning
+}
+
+void testBlockInCriticalSectionUniqueLock() {
+ std::mutex g_mutex;
+ std::not_real_lock<std::mutex> not_real_lock(g_mutex);
+ sleep(1); // no-warning
+
+ std::unique_lock<std::mutex> lock(g_mutex);
+ sleep(1); // expected-warning {{Call to blocking function 'sleep' inside of critical section}}
+}
+
+void testBlockInCriticalSectionUniqueLockNested() {
+ testBlockInCriticalSectionUniqueLock();
+ sleep(1); // no-warning
+}