diff options
Diffstat (limited to 'test/Analysis/block-in-critical-section.cpp')
-rw-r--r-- | test/Analysis/block-in-critical-section.cpp | 42 |
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 c65cc612cf73..fcf6188fc033 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 +} |