Skip to content

Commit 6119ae6

Browse files
author
git apple-llvm automerger
committed
Merge commit '228b3309880b' from llvm.org/main into next
2 parents 523a84d + 05d01ac commit 6119ae6

File tree

4 files changed

+216
-22
lines changed

4 files changed

+216
-22
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4012,6 +4012,7 @@ def AssertCapability : InheritableAttr {
40124012
let ParseArgumentsAsUnevaluated = 1;
40134013
let InheritEvenIfAlreadyPresent = 1;
40144014
let Args = [VariadicExprArgument<"Args">];
4015+
let AcceptsExprPack = 1;
40154016
let Accessors = [Accessor<"isShared",
40164017
[Clang<"assert_shared_capability", 0>,
40174018
GNU<"assert_shared_lock">]>];
@@ -4029,6 +4030,7 @@ def AcquireCapability : InheritableAttr {
40294030
let ParseArgumentsAsUnevaluated = 1;
40304031
let InheritEvenIfAlreadyPresent = 1;
40314032
let Args = [VariadicExprArgument<"Args">];
4033+
let AcceptsExprPack = 1;
40324034
let Accessors = [Accessor<"isShared",
40334035
[Clang<"acquire_shared_capability", 0>,
40344036
GNU<"shared_lock_function">]>];
@@ -4046,6 +4048,7 @@ def TryAcquireCapability : InheritableAttr {
40464048
let ParseArgumentsAsUnevaluated = 1;
40474049
let InheritEvenIfAlreadyPresent = 1;
40484050
let Args = [ExprArgument<"SuccessValue">, VariadicExprArgument<"Args">];
4051+
let AcceptsExprPack = 1;
40494052
let Accessors = [Accessor<"isShared",
40504053
[Clang<"try_acquire_shared_capability", 0>,
40514054
GNU<"shared_trylock_function">]>];
@@ -4063,6 +4066,7 @@ def ReleaseCapability : InheritableAttr {
40634066
let ParseArgumentsAsUnevaluated = 1;
40644067
let InheritEvenIfAlreadyPresent = 1;
40654068
let Args = [VariadicExprArgument<"Args">];
4069+
let AcceptsExprPack = 1;
40664070
let Accessors = [Accessor<"isShared",
40674071
[Clang<"release_shared_capability", 0>]>,
40684072
Accessor<"isGeneric",
@@ -4077,6 +4081,7 @@ def RequiresCapability : InheritableAttr {
40774081
Clang<"requires_shared_capability", 0>,
40784082
Clang<"shared_locks_required", 0>];
40794083
let Args = [VariadicExprArgument<"Args">];
4084+
let AcceptsExprPack = 1;
40804085
let LateParsed = LateAttrParseStandard;
40814086
let TemplateDependent = 1;
40824087
let ParseArgumentsAsUnevaluated = 1;
@@ -4119,6 +4124,7 @@ def PtGuardedBy : InheritableAttr {
41194124
def AcquiredAfter : InheritableAttr {
41204125
let Spellings = [GNU<"acquired_after">];
41214126
let Args = [VariadicExprArgument<"Args">];
4127+
let AcceptsExprPack = 1;
41224128
let LateParsed = LateAttrParseExperimentalExt;
41234129
let TemplateDependent = 1;
41244130
let ParseArgumentsAsUnevaluated = 1;
@@ -4130,6 +4136,7 @@ def AcquiredAfter : InheritableAttr {
41304136
def AcquiredBefore : InheritableAttr {
41314137
let Spellings = [GNU<"acquired_before">];
41324138
let Args = [VariadicExprArgument<"Args">];
4139+
let AcceptsExprPack = 1;
41334140
let LateParsed = LateAttrParseExperimentalExt;
41344141
let TemplateDependent = 1;
41354142
let ParseArgumentsAsUnevaluated = 1;
@@ -4151,6 +4158,7 @@ def LockReturned : InheritableAttr {
41514158
def LocksExcluded : InheritableAttr {
41524159
let Spellings = [GNU<"locks_excluded">];
41534160
let Args = [VariadicExprArgument<"Args">];
4161+
let AcceptsExprPack = 1;
41544162
let LateParsed = LateAttrParseStandard;
41554163
let TemplateDependent = 1;
41564164
let ParseArgumentsAsUnevaluated = 1;

clang/test/SemaCXX/warn-thread-safety-analysis.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ class SCOPED_LOCKABLE DoubleMutexLock {
5757
~DoubleMutexLock() UNLOCK_FUNCTION();
5858
};
5959

60+
template<typename Mu>
61+
class SCOPED_LOCKABLE TemplateMutexLock {
62+
public:
63+
TemplateMutexLock(Mu *mu) EXCLUSIVE_LOCK_FUNCTION(mu);
64+
~TemplateMutexLock() UNLOCK_FUNCTION();
65+
};
66+
67+
template<typename... Mus>
68+
class SCOPED_LOCKABLE VariadicMutexLock {
69+
public:
70+
VariadicMutexLock(Mus *...mus) EXCLUSIVE_LOCK_FUNCTION(mus...);
71+
~VariadicMutexLock() UNLOCK_FUNCTION();
72+
};
73+
6074
// The universal lock, written "*", allows checking to be selectively turned
6175
// off for a particular piece of code.
6276
void beginNoWarnOnReads() SHARED_LOCK_FUNCTION("*");
@@ -1821,6 +1835,18 @@ struct TestScopedLockable {
18211835
a = b + 1;
18221836
b = a + 1;
18231837
}
1838+
1839+
void foo6() {
1840+
TemplateMutexLock<Mutex> mulock1(&mu1), mulock2(&mu2);
1841+
a = b + 1;
1842+
b = a + 1;
1843+
}
1844+
1845+
void foo7() {
1846+
VariadicMutexLock<Mutex, Mutex> mulock(&mu1, &mu2);
1847+
a = b + 1;
1848+
b = a + 1;
1849+
}
18241850
};
18251851

18261852
} // end namespace test_scoped_lockable
@@ -3114,6 +3140,16 @@ class SCOPED_LOCKABLE ReaderMutexUnlock {
31143140
void Unlock() EXCLUSIVE_LOCK_FUNCTION();
31153141
};
31163142

3143+
template<typename... Mus>
3144+
class SCOPED_LOCKABLE VariadicMutexUnlock {
3145+
public:
3146+
VariadicMutexUnlock(Mus *...mus) EXCLUSIVE_UNLOCK_FUNCTION(mus...);
3147+
~VariadicMutexUnlock() EXCLUSIVE_UNLOCK_FUNCTION();
3148+
3149+
void Lock() EXCLUSIVE_UNLOCK_FUNCTION();
3150+
void Unlock() EXCLUSIVE_LOCK_FUNCTION();
3151+
};
3152+
31173153
Mutex mu;
31183154
int x GUARDED_BY(mu);
31193155
bool c;
@@ -3176,6 +3212,17 @@ void doubleUnlock() EXCLUSIVE_LOCKS_REQUIRED(mu) {
31763212
scope.Unlock(); // expected-warning {{releasing mutex 'mu' that was not held}}
31773213
}
31783214

3215+
Mutex mu2;
3216+
int y GUARDED_BY(mu2);
3217+
3218+
void variadic() EXCLUSIVE_LOCKS_REQUIRED(mu, mu2) {
3219+
VariadicMutexUnlock<Mutex, Mutex> scope(&mu, &mu2);
3220+
x = 2; // expected-warning {{writing variable 'x' requires holding mutex 'mu' exclusively}}
3221+
y = 3; // expected-warning {{writing variable 'y' requires holding mutex 'mu2' exclusively}}
3222+
scope.Lock();
3223+
x = y = 4;
3224+
}
3225+
31793226
class SCOPED_LOCKABLE MutexLockUnlock {
31803227
public:
31813228
MutexLockUnlock(Mutex *mu1, Mutex *mu2) EXCLUSIVE_UNLOCK_FUNCTION(mu1) EXCLUSIVE_LOCK_FUNCTION(mu2);

clang/test/SemaCXX/warn-thread-safety-parsing.cpp

Lines changed: 147 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
// RUN: %clang_cc1 -fsyntax-only -I%S/Inputs -verify -Wthread-safety %s
2-
// RUN: %clang_cc1 -fsyntax-only -I%S/Inputs -verify -Wthread-safety -std=c++98 %s
3-
// RUN: %clang_cc1 -fsyntax-only -I%S/Inputs -verify -Wthread-safety -std=c++11 %s -D CPP11
4-
5-
#include <warn-thread-safety-parsing.h>
1+
// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++98 %s
3+
// RUN: %clang_cc1 -fsyntax-only -verify -Wthread-safety -std=c++11 %s
64

75
#define LOCKABLE __attribute__ ((lockable))
86
#define SCOPED_LOCKABLE __attribute__ ((scoped_lockable))
@@ -658,6 +656,24 @@ int elf_function_bad_6(Mutex x, Mutex y) EXCLUSIVE_LOCK_FUNCTION(0); // \
658656
int elf_function_bad_7() EXCLUSIVE_LOCK_FUNCTION(0); // \
659657
// expected-error {{'exclusive_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
660658

659+
template<typename Mu>
660+
int elf_template(Mu& mu) EXCLUSIVE_LOCK_FUNCTION(mu) {}
661+
662+
template int elf_template<Mutex>(Mutex&);
663+
// FIXME: warn on template instantiation.
664+
template int elf_template<UnlockableMu>(UnlockableMu&);
665+
666+
#if __cplusplus >= 201103
667+
668+
template<typename... Mus>
669+
int elf_variadic_template(Mus&... mus) EXCLUSIVE_LOCK_FUNCTION(mus...) {}
670+
671+
template int elf_variadic_template<Mutex, Mutex>(Mutex&, Mutex&);
672+
// FIXME: warn on template instantiation.
673+
template int elf_variadic_template<Mutex, UnlockableMu>(Mutex&, UnlockableMu&);
674+
675+
#endif
676+
661677

662678
//-----------------------------------------//
663679
// Shared Lock Function (slf)
@@ -734,6 +750,24 @@ int slf_function_bad_6(Mutex x, Mutex y) SHARED_LOCK_FUNCTION(0); // \
734750
int slf_function_bad_7() SHARED_LOCK_FUNCTION(0); // \
735751
// expected-error {{'shared_lock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
736752

753+
template<typename Mu>
754+
int slf_template(Mu& mu) SHARED_LOCK_FUNCTION(mu) {}
755+
756+
template int slf_template<Mutex>(Mutex&);
757+
// FIXME: warn on template instantiation.
758+
template int slf_template<UnlockableMu>(UnlockableMu&);
759+
760+
#if __cplusplus >= 201103
761+
762+
template<typename... Mus>
763+
int slf_variadic_template(Mus&... mus) SHARED_LOCK_FUNCTION(mus...) {}
764+
765+
template int slf_variadic_template<Mutex, Mutex>(Mutex&, Mutex&);
766+
// FIXME: warn on template instantiation.
767+
template int slf_variadic_template<Mutex, UnlockableMu>(Mutex&, UnlockableMu&);
768+
769+
#endif
770+
737771

738772
//-----------------------------------------//
739773
// Exclusive TryLock Function (etf)
@@ -811,6 +845,24 @@ int etf_function_bad_5() EXCLUSIVE_TRYLOCK_FUNCTION(1, muDoublePointer); // \
811845
int etf_function_bad_6() EXCLUSIVE_TRYLOCK_FUNCTION(1, umu); // \
812846
// expected-warning {{'exclusive_trylock_function' attribute requires arguments whose type is annotated with 'capability' attribute}}
813847

848+
template<typename Mu>
849+
int etf_template(Mu& mu) EXCLUSIVE_TRYLOCK_FUNCTION(1, mu) {}
850+
851+
template int etf_template<Mutex>(Mutex&);
852+
// FIXME: warn on template instantiation.
853+
template int etf_template<UnlockableMu>(UnlockableMu&);
854+
855+
#if __cplusplus >= 201103
856+
857+
template<typename... Mus>
858+
int etf_variadic_template(Mus&... mus) EXCLUSIVE_TRYLOCK_FUNCTION(1, mus...) {}
859+
860+
template int etf_variadic_template<Mutex, Mutex>(Mutex&, Mutex&);
861+
// FIXME: warn on template instantiation.
862+
template int etf_variadic_template<Mutex, UnlockableMu>(Mutex&, UnlockableMu&);
863+
864+
#endif
865+
814866

815867
//-----------------------------------------//
816868
// Shared TryLock Function (stf)
@@ -889,6 +941,24 @@ int stf_function_bad_5() SHARED_TRYLOCK_FUNCTION(1, muDoublePointer); // \
889941
int stf_function_bad_6() SHARED_TRYLOCK_FUNCTION(1, umu); // \
890942
// expected-warning {{'shared_trylock_function' attribute requires arguments whose type is annotated with 'capability' attribute}}
891943

944+
template<typename Mu>
945+
int stf_template(Mu& mu) SHARED_TRYLOCK_FUNCTION(1, mu) {}
946+
947+
template int stf_template<Mutex>(Mutex&);
948+
// FIXME: warn on template instantiation.
949+
template int stf_template<UnlockableMu>(UnlockableMu&);
950+
951+
#if __cplusplus >= 201103
952+
953+
template<typename... Mus>
954+
int stf_variadic_template(Mus&... mus) SHARED_TRYLOCK_FUNCTION(1, mus...) {}
955+
956+
template int stf_variadic_template<Mutex, Mutex>(Mutex&, Mutex&);
957+
// FIXME: warn on template instantiation.
958+
template int stf_variadic_template<Mutex, UnlockableMu>(Mutex&, UnlockableMu&);
959+
960+
#endif
961+
892962

893963
//-----------------------------------------//
894964
// Unlock Function (uf)
@@ -968,6 +1038,24 @@ int uf_function_bad_6(Mutex x, Mutex y) UNLOCK_FUNCTION(0); // \
9681038
int uf_function_bad_7() UNLOCK_FUNCTION(0); // \
9691039
// expected-error {{'unlock_function' attribute parameter 1 is out of bounds: no parameters to index into}}
9701040

1041+
template<typename Mu>
1042+
int uf_template(Mu& mu) UNLOCK_FUNCTION(mu) {}
1043+
1044+
template int uf_template<Mutex>(Mutex&);
1045+
// FIXME: warn on template instantiation.
1046+
template int uf_template<UnlockableMu>(UnlockableMu&);
1047+
1048+
#if __cplusplus >= 201103
1049+
1050+
template<typename... Mus>
1051+
int uf_variadic_template(Mus&... mus) UNLOCK_FUNCTION(mus...) {}
1052+
1053+
template int uf_variadic_template<Mutex, Mutex>(Mutex&, Mutex&);
1054+
// FIXME: warn on template instantiation.
1055+
template int uf_variadic_template<Mutex, UnlockableMu>(Mutex&, UnlockableMu&);
1056+
1057+
#endif
1058+
9711059

9721060
//-----------------------------------------//
9731061
// Lock Returned (lr)
@@ -1103,6 +1191,23 @@ int le_function_bad_3() LOCKS_EXCLUDED(muDoublePointer); // \
11031191
int le_function_bad_4() LOCKS_EXCLUDED(umu); // \
11041192
// expected-warning {{'locks_excluded' attribute requires arguments whose type is annotated with 'capability' attribute}}
11051193

1194+
template<typename Mu>
1195+
int le_template(Mu& mu) LOCKS_EXCLUDED(mu) {}
1196+
1197+
template int le_template<Mutex>(Mutex&);
1198+
// FIXME: warn on template instantiation.
1199+
template int le_template<UnlockableMu>(UnlockableMu&);
1200+
1201+
#if __cplusplus >= 201103
1202+
1203+
template<typename... Mus>
1204+
int le_variadic_template(Mus&... mus) LOCKS_EXCLUDED(mus...) {}
1205+
1206+
template int le_variadic_template<Mutex, Mutex>(Mutex&, Mutex&);
1207+
// FIXME: warn on template instantiation.
1208+
template int le_variadic_template<Mutex, UnlockableMu>(Mutex&, UnlockableMu&);
1209+
1210+
#endif
11061211

11071212

11081213
//-----------------------------------------//
@@ -1171,6 +1276,24 @@ int elr_function_bad_3() EXCLUSIVE_LOCKS_REQUIRED(muDoublePointer); // \
11711276
int elr_function_bad_4() EXCLUSIVE_LOCKS_REQUIRED(umu); // \
11721277
// expected-warning {{'exclusive_locks_required' attribute requires arguments whose type is annotated with 'capability' attribute}}
11731278

1279+
template<typename Mu>
1280+
int elr_template(Mu& mu) EXCLUSIVE_LOCKS_REQUIRED(mu) {}
1281+
1282+
template int elr_template<Mutex>(Mutex&);
1283+
// FIXME: warn on template instantiation.
1284+
template int elr_template<UnlockableMu>(UnlockableMu&);
1285+
1286+
#if __cplusplus >= 201103
1287+
1288+
template<typename... Mus>
1289+
int elr_variadic_template(Mus&... mus) EXCLUSIVE_LOCKS_REQUIRED(mus...) {}
1290+
1291+
template int elr_variadic_template<Mutex, Mutex>(Mutex&, Mutex&);
1292+
// FIXME: warn on template instantiation.
1293+
template int elr_variadic_template<Mutex, UnlockableMu>(Mutex&, UnlockableMu&);
1294+
1295+
#endif
1296+
11741297

11751298

11761299

@@ -1240,6 +1363,24 @@ int slr_function_bad_3() SHARED_LOCKS_REQUIRED(muDoublePointer); // \
12401363
int slr_function_bad_4() SHARED_LOCKS_REQUIRED(umu); // \
12411364
// expected-warning {{'shared_locks_required' attribute requires arguments whose type is annotated with 'capability' attribute}}
12421365

1366+
template<typename Mu>
1367+
int slr_template(Mu& mu) SHARED_LOCKS_REQUIRED(mu) {}
1368+
1369+
template int slr_template<Mutex>(Mutex&);
1370+
// FIXME: warn on template instantiation.
1371+
template int slr_template<UnlockableMu>(UnlockableMu&);
1372+
1373+
#if __cplusplus >= 201103
1374+
1375+
template<typename... Mus>
1376+
int slr_variadic_template(Mus&... mus) SHARED_LOCKS_REQUIRED(mus...) {}
1377+
1378+
template int slr_variadic_template<Mutex, Mutex>(Mutex&, Mutex&);
1379+
// FIXME: warn on template instantiation.
1380+
template int slr_variadic_template<Mutex, UnlockableMu>(Mutex&, UnlockableMu&);
1381+
1382+
#endif
1383+
12431384

12441385
//-----------------------------------------//
12451386
// Regression tests for unusual cases.
@@ -1597,7 +1738,7 @@ class Foo {
15971738
} // end namespace FunctionAttributesInsideClass_ICE_Test
15981739

15991740

1600-
#ifdef CPP11
1741+
#if __cplusplus >= 201103
16011742
namespace CRASH_POST_R301735 {
16021743
class SomeClass {
16031744
public:

0 commit comments

Comments
 (0)