summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-02-03 04:45:26 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-02-03 04:45:26 +0000
commit922866783b073b455017c1c321cc49bd8d33b868 (patch)
tree4c9d6643e0890c80ca4b3c65992ebb8584628368 /clang/test/SemaCXX/warn-thread-safety-analysis.cpp
parentf0b08445f6015e09a00877173b8f82b3d933faf9 (diff)
downloadbcm5719-llvm-922866783b073b455017c1c321cc49bd8d33b868.tar.gz
bcm5719-llvm-922866783b073b455017c1c321cc49bd8d33b868.zip
Thread safety analysis:
* When we detect that a CFG block has inconsistent lock sets, point the diagnostic at the location where we found the inconsistency, and point a note at somewhere the inconsistently-locked mutex was locked. * Fix the wording of the normal (non-loop, non-end-of-function) case of this diagnostic to not suggest that the mutex is going out of scope. * Fix the diagnostic emission code to keep a warning and its note together when sorting the diagnostics into source location order. llvm-svn: 149669
Diffstat (limited to 'clang/test/SemaCXX/warn-thread-safety-analysis.cpp')
-rw-r--r--clang/test/SemaCXX/warn-thread-safety-analysis.cpp118
1 files changed, 70 insertions, 48 deletions
diff --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
index 634a2334307..54e5795615f 100644
--- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -172,30 +172,29 @@ void sls_fun_bad_2() {
}
void sls_fun_bad_3() {
- sls_mu.Lock(); // \
- // expected-warning{{mutex 'sls_mu' is still locked at the end of function}}
-}
+ sls_mu.Lock(); // expected-note {{mutex acquired here}}
+} // expected-warning{{mutex 'sls_mu' is still locked at the end of function}}
void sls_fun_bad_4() {
if (getBool())
sls_mu.Lock(); // \
- // expected-warning{{mutex 'sls_mu' is still locked at the end of its scope}}
+ expected-warning{{mutex 'sls_mu2' is not locked on every path through here}} \
+ expected-note{{mutex acquired here}}
+
else
sls_mu2.Lock(); // \
- // expected-warning{{mutex 'sls_mu2' is still locked at the end of its scope}}
-}
+ expected-note{{mutex acquired here}}
+} // expected-warning{{mutex 'sls_mu' is not locked on every path through here}}
void sls_fun_bad_5() {
- sls_mu.Lock(); // \
- // expected-warning{{mutex 'sls_mu' is still locked at the end of its scope}}
+ sls_mu.Lock(); // expected-note {{mutex acquired here}}
if (getBool())
sls_mu.Unlock();
-}
+} // expected-warning{{mutex 'sls_mu' is not locked on every path through here}}
void sls_fun_bad_6() {
if (getBool()) {
- sls_mu.Lock(); // \
- // expected-warning{{mutex 'sls_mu' is still locked at the end of its scope}}
+ sls_mu.Lock(); // expected-note {{mutex acquired here}}
} else {
if (getBool()) {
getBool(); // EMPTY
@@ -204,7 +203,8 @@ void sls_fun_bad_6() {
}
}
sls_mu.Unlock(); // \
- // expected-warning{{unlocking 'sls_mu' that was not locked}}
+ expected-warning{{mutex 'sls_mu' is not locked on every path through here}}\
+ expected-warning{{unlocking 'sls_mu' that was not locked}}
}
void sls_fun_bad_7() {
@@ -213,19 +213,20 @@ void sls_fun_bad_7() {
sls_mu.Unlock();
if (getBool()) {
if (getBool()) {
- continue;
+ continue; // \
+ expected-warning{{expecting mutex 'sls_mu' to be locked at start of each loop}}
}
}
- sls_mu.Lock(); // \
- // expected-warning{{expecting mutex 'sls_mu' to be locked at start of each loop}}
+ sls_mu.Lock(); // expected-note {{mutex acquired here}}
}
sls_mu.Unlock();
}
void sls_fun_bad_8() {
- sls_mu.Lock(); // \
- // expected-warning{{expecting mutex 'sls_mu' to be locked at start of each loop}}
- do {
+ sls_mu.Lock(); // expected-note{{mutex acquired here}}
+
+ // FIXME: TERRIBLE SOURCE LOCATION!
+ do { // expected-warning{{expecting mutex 'sls_mu' to be locked at start of each loop}}
sls_mu.Unlock();
} while (getBool());
}
@@ -233,37 +234,35 @@ void sls_fun_bad_8() {
void sls_fun_bad_9() {
do {
sls_mu.Lock(); // \
- // expected-warning{{expecting mutex 'sls_mu' to be locked at start of each loop}}
+ // expected-warning{{expecting mutex 'sls_mu' to be locked at start of each loop}} \
+ // expected-note{{mutex acquired here}}
} while (getBool());
sls_mu.Unlock();
}
void sls_fun_bad_10() {
- sls_mu.Lock(); // \
- // expected-warning{{mutex 'sls_mu' is still locked at the end of function}} \
- // expected-warning{{expecting mutex 'sls_mu' to be locked at start of each loop}}
+ sls_mu.Lock(); // expected-note 2{{mutex acquired here}}
while(getBool()) {
- sls_mu.Unlock();
+ sls_mu.Unlock(); // expected-warning{{expecting mutex 'sls_mu' to be locked at start of each loop}}
}
-}
+} // expected-warning{{mutex 'sls_mu' is still locked at the end of function}}
void sls_fun_bad_11() {
- while (getBool()) {
- sls_mu.Lock(); // \
- // expected-warning{{expecting mutex 'sls_mu' to be locked at start of each loop}}
+ while (getBool()) { // \
+ expected-warning{{expecting mutex 'sls_mu' to be locked at start of each loop}}
+ sls_mu.Lock(); // expected-note {{mutex acquired here}}
}
sls_mu.Unlock(); // \
// expected-warning{{unlocking 'sls_mu' that was not locked}}
}
void sls_fun_bad_12() {
- sls_mu.Lock(); // \
- // expected-warning{{mutex 'sls_mu' is still locked at the end of its scope}}
+ sls_mu.Lock(); // expected-note {{mutex acquired here}}
while (getBool()) {
sls_mu.Unlock();
if (getBool()) {
if (getBool()) {
- break;
+ break; // expected-warning{{mutex 'sls_mu' is not locked on every path through here}}
}
}
sls_mu.Lock();
@@ -303,9 +302,8 @@ void aa_fun_bad_2() {
}
void aa_fun_bad_3() {
- glock.globalLock(); // \
- // expected-warning{{mutex 'aa_mu' is still locked at the end of function}}
-}
+ glock.globalLock(); // expected-note{{mutex acquired here}}
+} // expected-warning{{mutex 'aa_mu' is still locked at the end of function}}
//--------------------------------------------------//
// Regression tests for unusual method names
@@ -316,22 +314,18 @@ Mutex wmu;
// Test diagnostics for other method names.
class WeirdMethods {
WeirdMethods() {
- wmu.Lock(); // \
- // expected-warning {{mutex 'wmu' is still locked at the end of function}}
- }
+ wmu.Lock(); // expected-note {{mutex acquired here}}
+ } // expected-warning {{mutex 'wmu' is still locked at the end of function}}
~WeirdMethods() {
- wmu.Lock(); // \
- // expected-warning {{mutex 'wmu' is still locked at the end of function}}
- }
+ wmu.Lock(); // expected-note {{mutex acquired here}}
+ } // expected-warning {{mutex 'wmu' is still locked at the end of function}}
void operator++() {
- wmu.Lock(); // \
- // expected-warning {{mutex 'wmu' is still locked at the end of function}}
- }
+ wmu.Lock(); // expected-note {{mutex acquired here}}
+ } // expected-warning {{mutex 'wmu' is still locked at the end of function}}
operator int*() {
- wmu.Lock(); // \
- // expected-warning {{mutex 'wmu' is still locked at the end of function}}
+ wmu.Lock(); // expected-note {{mutex acquired here}}
return 0;
- }
+ } // expected-warning {{mutex 'wmu' is still locked at the end of function}}
};
//-----------------------------------------------//
@@ -1484,11 +1478,10 @@ namespace substitution_test {
void bar3(MyData* d1, MyData* d2) {
DataLocker dlr;
- dlr.lockData(d1); // \
- // expected-warning {{mutex 'mu' is still locked at the end of function}}
+ dlr.lockData(d1); // expected-note {{mutex acquired here}}
dlr.unlockData(d2); // \
// expected-warning {{unlocking 'mu' that was not locked}}
- }
+ } // expected-warning {{mutex 'mu' is still locked at the end of function}}
void bar4(MyData* d1, MyData* d2) {
DataLocker dlr;
@@ -1914,3 +1907,32 @@ void test() {
}
};
+
+namespace GoingNative {
+
+ struct __attribute__((lockable)) mutex {
+ void lock() __attribute__((exclusive_lock_function));
+ void unlock() __attribute__((unlock_function));
+ // ...
+ };
+ bool foo();
+ bool bar();
+ mutex m;
+ void test() {
+ m.lock();
+ while (foo()) {
+ m.unlock();
+ // ...
+ if (bar()) {
+ // ...
+ if (foo())
+ continue; // expected-warning {{expecting mutex 'm' to be locked at start of each loop}}
+ //...
+ }
+ // ...
+ m.lock(); // expected-note {{mutex acquired here}}
+ }
+ m.unlock();
+ }
+
+}
OpenPOWER on IntegriCloud