Skip to content

Commit bd4eb50

Browse files
committed
Extract regression test into a separate file
1 parent 78c98c5 commit bd4eb50

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %clang_cc1 -verify -fsyntax-only -Wthread-safety %s
2+
3+
#ifndef HEADER
4+
#define HEADER
5+
6+
#define LOCKABLE __attribute__ ((lockable))
7+
#define EXCLUSIVE_LOCK_FUNCTION(...) __attribute__ ((exclusive_lock_function(__VA_ARGS__)))
8+
9+
class LOCKABLE Mutex{};
10+
11+
template<typename T>
12+
struct lock_guard {
13+
lock_guard<T>(T) {}
14+
~lock_guard<T>() {}
15+
};
16+
template<typename T>
17+
struct unique_lock {
18+
unique_lock<T>(T) {}
19+
~unique_lock<T>() {}
20+
};
21+
22+
template <class T, class... Ts>
23+
void LockMutexes(T &m, Ts &...ms) EXCLUSIVE_LOCK_FUNCTION(m, ms...);
24+
25+
#else
26+
27+
Mutex m0, m1;
28+
void non_local_mutex_held() {
29+
LockMutexes(m0, m1); // expected-note {{mutex acquired here}} \
30+
// expected-note {{mutex acquired here}}
31+
} // expected-warning{{mutex 'm0' is still held at the end of function}} \
32+
// expected-warning{{mutex 'm1' is still held at the end of function}}
33+
34+
void no_local_mutex_held_warning() {
35+
Mutex local_m0;
36+
Mutex local_m1;
37+
LockMutexes(local_m0, local_m1);
38+
} // No warnings expected at end of function scope as the mutexes are function local.
39+
40+
void no_local_unique_locks_held_warning() {
41+
unique_lock<Mutex> ul0(m0);
42+
unique_lock<Mutex> ul1(m1);
43+
LockMutexes(ul0, ul1);
44+
} // No warnings expected at end of function scope as the unique_locks held are function local.
45+
#endif

clang/test/PCH/thread-safety-attrs.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,6 @@ class SCOPED_LOCKABLE ReleasableMutexLock {
6060
void Release() UNLOCK_FUNCTION();
6161
};
6262

63-
template<typename T>
64-
struct lock_guard {
65-
lock_guard<T>(T) {}
66-
~lock_guard<T>() {}
67-
};
68-
template<typename T>
69-
struct unique_lock {
70-
unique_lock<T>(T) {}
71-
~unique_lock<T>() {}
72-
};
73-
74-
template <class T, class... Ts>
75-
void LockMutexes(T &m, Ts &...ms) __attribute__((exclusive_lock_function(m, ms...)));
76-
7763

7864
// The universal lock, written "*", allows checking to be selectively turned
7965
// off for a particular piece of code.
@@ -330,23 +316,4 @@ void sls_fun_bad_12() {
330316
expected-warning{{releasing mutex 'sls_mu' that was not held}}
331317
}
332318

333-
Mutex m0, m1;
334-
void non_local_mutex_held() {
335-
LockMutexes(m0, m1); // expected-note {{mutex acquired here}} \
336-
// expected-note {{mutex acquired here}}
337-
} // expected-warning{{mutex 'm0' is still held at the end of function}} \
338-
// expected-warning{{mutex 'm1' is still held at the end of function}}
339-
340-
void no_local_mutex_held_warning() {
341-
Mutex local_m0;
342-
Mutex local_m1;
343-
LockMutexes(local_m0, local_m1);
344-
} // No warnings expected at end of function scope as the mutexes are function local.
345-
346-
void no_local_unique_locks_held_warning() {
347-
unique_lock<Mutex> ul0(m0);
348-
unique_lock<Mutex> ul1(m1);
349-
LockMutexes(ul0, ul1);
350-
} // No warnings expected at end of function scope as the unique_locks held are function local.
351-
352319
#endif

0 commit comments

Comments
 (0)