1 2 // RUN: %clang_analyze_cc1 \ 3 // RUN: -analyzer-checker=unix.BlockInCriticalSection \ 4 // RUN: -std=c++11 \ 5 // RUN: -analyzer-output text \ 6 // RUN: -verify %s 7 8 unsigned int sleep(unsigned int seconds) {return 0;} 9 namespace std { 10 namespace __detail { 11 class __mutex_base { 12 public: 13 void lock(); 14 }; 15 } // namespace __detail 16 17 class mutex : public __detail::__mutex_base{ 18 public: 19 void unlock(); 20 bool try_lock(); 21 }; 22 } // namespace std 23 24 void gh_99628() { 25 std::mutex m; 26 m.lock(); 27 // expected-note@-1 {{Entering critical section here}} 28 sleep(10); 29 // expected-warning@-1 {{Call to blocking function 'sleep' inside of critical section}} 30 // expected-note@-2 {{Call to blocking function 'sleep' inside of critical section}} 31 m.unlock(); 32 } 33 34 void no_false_positive_gh_104241() { 35 std::mutex m; 36 m.lock(); 37 // If inheritance not handled properly, this unlock might not match the lock 38 // above because technically they act on different memory regions: 39 // __mutex_base and mutex. 40 m.unlock(); 41 sleep(10); // no-warning 42 } 43