Tests: Make it mt-safe to call operators on guarded and local objects. (#3821)

This commit is contained in:
Mariusz Glebocki 2022-12-19 16:53:28 +01:00 committed by GitHub
parent 982fa3d7bb
commit cb413aa264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 513 additions and 500 deletions

View File

@ -318,8 +318,14 @@ class CallAnnotationsValidator:
def find_object_ref(node):
try:
node = next(node.get_children())
if node.kind == CursorKind.DECL_REF_EXPR:
# Operator on an argument or local object
return node
if node.kind != CursorKind.MEMBER_REF_EXPR:
return None
if node.referenced and node.referenced.kind == CursorKind.FIELD_DECL:
# Operator on a member object
return node
node = next(node.get_children())
if node.kind == CursorKind.UNEXPOSED_EXPR:
node = next(node.get_children())

View File

@ -104,6 +104,8 @@ struct GuardMe {
void safe_if_guarded_or_local() {}
operator int() const { return 4; }
GuardMe& operator+=(int) { return *this; }
};
class TestClass {
@ -250,20 +252,24 @@ public:
void guarded_by_test_pass(GuardMe& guardme_arg) VL_MT_SAFE {
guardme_arg.safe_if_guarded_or_local();
int a = guardme_arg;
guardme_arg += 4;
m_mtx.lock();
m_guardme.safe_if_guarded_or_local();
int b = m_guardme;
m_guardme += 4;
m_mtx.unlock();
GuardMe guardme_local;
guardme_local.safe_if_guarded_or_local();
int c = guardme_local;
guardme_local += 4;
}
void guarded_by_test_fail() VL_MT_SAFE {
m_guardme_unguarded.safe_if_guarded_or_local();
int a = m_guardme_unguarded;
m_guardme_unguarded += 4;
}
};

File diff suppressed because it is too large Load Diff