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"); }
}];
}
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"); }
}];
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits