[PATCH] D72635: Allow arbitrary capability name in Thread Safety Analysis
Etienne Pierre-Doray via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 21 09:59:09 PST 2020
eti-p-doray updated this revision to Diff 239362.
eti-p-doray added a comment.
Added test with custom capability name.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72635/new/
https://reviews.llvm.org/D72635
Files:
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Sema/attr-capabilities.c
Index: clang/test/Sema/attr-capabilities.c
===================================================================
--- clang/test/Sema/attr-capabilities.c
+++ clang/test/Sema/attr-capabilities.c
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -Wthread-safety -verify %s
+typedef int __attribute__((capability("role"))) ThreadRole;
typedef int __attribute__((capability("role"))) ThreadRole;
struct __attribute__((shared_capability("mutex"))) Mutex {};
struct NotACapability {};
@@ -8,8 +9,8 @@
union __attribute__((capability("mutex"))) MutexUnion { int a; char* b; };
typedef union { int a; char* b; } __attribute__((capability("mutex"))) MutexUnion2;
-// Test an invalid capability name
-struct __attribute__((capability("wrong"))) IncorrectName {}; // expected-warning {{invalid capability name 'wrong'; capability name must be 'mutex' or 'role'}}
+// Test a different capability name
+struct __attribute__((capability("custom"))) CustomName {};
int Test1 __attribute__((capability("test1"))); // expected-error {{'capability' attribute only applies to structs, unions, classes, and typedefs}}
int Test2 __attribute__((shared_capability("test2"))); // expected-error {{'shared_capability' attribute only applies to structs, unions, classes, and typedefs}}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6199,11 +6199,6 @@
!S.checkStringLiteralArgumentAttr(AL, 0, N, &LiteralLoc))
return;
- // Currently, there are only two names allowed for a capability: role and
- // mutex (case insensitive). Diagnose other capability names.
- if (!N.equals_lower("mutex") && !N.equals_lower("role"))
- S.Diag(LiteralLoc, diag::warn_invalid_capability_name) << N;
-
D->addAttr(::new (S.Context) CapabilityAttr(S.Context, AL, N));
}
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3195,9 +3195,6 @@
InGroup<DiagGroup<"unsupported-availability-guard">>;
// Thread Safety Attributes
-def warn_invalid_capability_name : Warning<
- "invalid capability name '%0'; capability name must be 'mutex' or 'role'">,
- InGroup<ThreadSafetyAttributes>, DefaultIgnore;
def warn_thread_attribute_ignored : Warning<
"ignoring %0 attribute because its argument is invalid">,
InGroup<ThreadSafetyAttributes>, DefaultIgnore;
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2562,10 +2562,6 @@
let Accessors = [Accessor<"isShared",
[Clang<"shared_capability", 0>]>];
let Documentation = [Undocumented];
- let AdditionalMembers = [{
- bool isMutex() const { return getName().equals_lower("mutex"); }
- bool isRole() const { return getName().equals_lower("role"); }
- }];
}
def AssertCapability : InheritableAttr {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72635.239362.patch
Type: text/x-patch
Size: 3134 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200121/b121444e/attachment-0001.bin>
More information about the cfe-commits
mailing list