From 5260bc2497bb593ed4a01de5cfe84ed6f7b529b1 Mon Sep 17 00:00:00 2001 From: Etienne Pierre-Doray Date: Tue, 21 Jan 2020 15:43:17 -0500 Subject: [PATCH] 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 --- clang/include/clang/Basic/Attr.td | 4 ---- clang/include/clang/Basic/DiagnosticSemaKinds.td | 3 --- clang/lib/Sema/SemaDeclAttr.cpp | 5 ----- clang/test/Sema/attr-capabilities.c | 5 +++-- 4 files changed, 3 insertions(+), 14 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 10db2a868dce6d..7d01181e7c0188 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -2567,10 +2567,6 @@ def Capability : InheritableAttr { 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 { diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index a4d0427108587e..b87419d393e2c8 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3252,9 +3252,6 @@ def warn_at_available_unchecked_use : Warning< InGroup>; // Thread Safety Attributes -def warn_invalid_capability_name : Warning< - "invalid capability name '%0'; capability name must be 'mutex' or 'role'">, - InGroup, DefaultIgnore; def warn_thread_attribute_ignored : Warning< "ignoring %0 attribute because its argument is invalid">, InGroup, DefaultIgnore; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 77194de87ba424..040a2695643346 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -6195,11 +6195,6 @@ static void handleCapabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { !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)); } diff --git a/clang/test/Sema/attr-capabilities.c b/clang/test/Sema/attr-capabilities.c index 8bfc4a50654326..03cebe2f6596b0 100644 --- a/clang/test/Sema/attr-capabilities.c +++ b/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 @@ struct NotACapability {}; 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}}