brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 01975bf Raw
43 lines · cpp
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 %s7 8unsigned int sleep(unsigned int seconds) {return 0;}9namespace std {10namespace __detail {11class __mutex_base {12public:13  void lock();14};15} // namespace __detail16 17class mutex : public __detail::__mutex_base{18public:19  void unlock();20  bool try_lock();21};22} // namespace std23 24void 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 34void no_false_positive_gh_104241() {35  std::mutex m;36  m.lock();37  // If inheritance not handled properly, this unlock might not match the lock38  // above because technically they act on different memory regions:39  // __mutex_base and mutex.40  m.unlock();41  sleep(10); // no-warning42}43