Skip to content

Commit 5260bc2

Browse files
etiennep-chromiumAaronBallman
authored andcommitted
Allow arbitrary capability name in Thread Safety Analysis
Restricting the names of capabilities to only "role" or "mutex" makes for awkward diagnostic text, such as with: https://chromium-review.googlesource.com/c/chromium/src/+/1948098/19/base/sequence_checker_unittest.nc#33
1 parent b6c62ef commit 5260bc2

File tree

4 files changed

+3
-14
lines changed

4 files changed

+3
-14
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,10 +2567,6 @@ def Capability : InheritableAttr {
25672567
let Accessors = [Accessor<"isShared",
25682568
[Clang<"shared_capability", 0>]>];
25692569
let Documentation = [Undocumented];
2570-
let AdditionalMembers = [{
2571-
bool isMutex() const { return getName().equals_lower("mutex"); }
2572-
bool isRole() const { return getName().equals_lower("role"); }
2573-
}];
25742570
}
25752571

25762572
def AssertCapability : InheritableAttr {

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3252,9 +3252,6 @@ def warn_at_available_unchecked_use : Warning<
32523252
InGroup<DiagGroup<"unsupported-availability-guard">>;
32533253

32543254
// Thread Safety Attributes
3255-
def warn_invalid_capability_name : Warning<
3256-
"invalid capability name '%0'; capability name must be 'mutex' or 'role'">,
3257-
InGroup<ThreadSafetyAttributes>, DefaultIgnore;
32583255
def warn_thread_attribute_ignored : Warning<
32593256
"ignoring %0 attribute because its argument is invalid">,
32603257
InGroup<ThreadSafetyAttributes>, DefaultIgnore;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6195,11 +6195,6 @@ static void handleCapabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
61956195
!S.checkStringLiteralArgumentAttr(AL, 0, N, &LiteralLoc))
61966196
return;
61976197

6198-
// Currently, there are only two names allowed for a capability: role and
6199-
// mutex (case insensitive). Diagnose other capability names.
6200-
if (!N.equals_lower("mutex") && !N.equals_lower("role"))
6201-
S.Diag(LiteralLoc, diag::warn_invalid_capability_name) << N;
6202-
62036198
D->addAttr(::new (S.Context) CapabilityAttr(S.Context, AL, N));
62046199
}
62056200

clang/test/Sema/attr-capabilities.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clang_cc1 -fsyntax-only -Wthread-safety -verify %s
22

3+
typedef int __attribute__((capability("role"))) ThreadRole;
34
typedef int __attribute__((capability("role"))) ThreadRole;
45
struct __attribute__((shared_capability("mutex"))) Mutex {};
56
struct NotACapability {};
@@ -8,8 +9,8 @@ struct NotACapability {};
89
union __attribute__((capability("mutex"))) MutexUnion { int a; char* b; };
910
typedef union { int a; char* b; } __attribute__((capability("mutex"))) MutexUnion2;
1011

11-
// Test an invalid capability name
12-
struct __attribute__((capability("wrong"))) IncorrectName {}; // expected-warning {{invalid capability name 'wrong'; capability name must be 'mutex' or 'role'}}
12+
// Test a different capability name
13+
struct __attribute__((capability("custom"))) CustomName {};
1314

1415
int Test1 __attribute__((capability("test1"))); // expected-error {{'capability' attribute only applies to structs, unions, classes, and typedefs}}
1516
int Test2 __attribute__((shared_capability("test2"))); // expected-error {{'shared_capability' attribute only applies to structs, unions, classes, and typedefs}}

0 commit comments

Comments
 (0)