[PATCH] D72635: Add "context" capability to Thread Safety Analysis

Etienne Pierre-Doray via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 13 11:32:04 PST 2020


eti-p-doray created this revision.
eti-p-doray added a reviewer: aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Main use case: 
Chromium has runtime "SequenceChecker" and "ThreadChecker" that enforce sequenced task context. Thread safety analysis can be used but neither "mutex" nor "role" seem appropriate for meaningful error messages.
https://chromium-review.googlesource.com/c/chromium/src/+/1948098


Repository:
  rC Clang

https://reviews.llvm.org/D72635

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclAttr.cpp


Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6199,10 +6199,12 @@
       !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"))
+  // Currently, there are only 3 names allowed for a capability: role,
+  // mutex and context (case insensitive). Diagnose other capability names.
+  if (!N.equals_lower("mutex") && !N.equals_lower("role") &&
+      !N.equals_lower("context")) {
     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
@@ -3196,7 +3196,8 @@
 
 // Thread Safety Attributes
 def warn_invalid_capability_name : Warning<
-  "invalid capability name '%0'; capability name must be 'mutex' or 'role'">,
+  "invalid capability name '%0'; capability name must be 'mutex', 'role' or "
+  "'context'">,
   InGroup<ThreadSafetyAttributes>, DefaultIgnore;
 def warn_thread_attribute_ignored : Warning<
   "ignoring %0 attribute because its argument is invalid">,
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2565,6 +2565,7 @@
   let AdditionalMembers = [{
     bool isMutex() const { return getName().equals_lower("mutex"); }
     bool isRole() const { return getName().equals_lower("role"); }
+    bool isContext() const { return getName().equals_lower("context"); }
   }];
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72635.237738.patch
Type: text/x-patch
Size: 1998 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200113/94fedbdc/attachment-0001.bin>


More information about the cfe-commits mailing list