================
@@ -7548,6 +7534,66 @@ void testPointerAliasEscapeAndReset(Foo *f) {
ptr->mu.Unlock();
}
+struct LOCKABLE Entry;
+void getLockedEntry(Entry **entry) EXCLUSIVE_LOCK_FUNCTION(*entry);
+void useLockedEntry(Entry *entry) EXCLUSIVE_LOCKS_REQUIRED(entry);
+void unlockEntry(Entry *entry) UNLOCK_FUNCTION(entry);
+
+void testOutParamAcquireCap(Entry *in) {
+ Entry *entry = in;
+
+ // 'getLockedEntry' guarantees that '*entry' is locked after return:
+ getLockedEntry(&entry);
+ useLockedEntry(entry);
+ if (1) {
+ useLockedEntry(entry);
+ }
+ unlockEntry(entry);
+}
+
+void testOutParamAcquireCap_invalidation(Entry *in) {
+ Entry *entry = in;
+
+ // 'getLockedEntry' invalidates 'entry' at the pre-state and ensures
+ // 'entry' is locked at the post-state. So 'in' is not locked.
+ getLockedEntry(&entry); // expected-note{{mutex acquired here}}
+ useLockedEntry(in); // expected-warning{{calling function 'useLockedEntry'
requires holding mutex 'in' exclusively}}
+ unlockEntry(in); // expected-warning{{releasing mutex 'in' that was not
held}}
+} // expected-warning{{mutex 'entry' is still held at the end of function}}
+
+void allActions(Entry **e1, Entry **e2, Entry **e3, Entry **e4, Entry **e5)
+ EXCLUSIVE_LOCK_FUNCTION(*e1) EXCLUSIVE_LOCKS_REQUIRED(*e2)
+ UNLOCK_FUNCTION(*e3) ASSERT_EXCLUSIVE_LOCK(*e4) LOCKS_EXCLUDED(*e5);
----------------
melver wrote:
Can you also cover:
1. C++ reference out-parameters `Entry *&entry`.
2. Multi-argument acquisition attributes `EXCLUSIVE_LOCK_FUNCTION(*e1,
*e2)`
https://github.com/llvm/llvm-project/pull/210219
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits