Thread safety analysis: Always warn when dropping locks on back edges
authorAaron Puchert <aaron.puchert@sap.com>
Tue, 29 Jun 2021 21:46:43 +0000 (23:46 +0200)
committerAaron Puchert <aaron.puchert@sap.com>
Tue, 29 Jun 2021 21:56:52 +0000 (23:56 +0200)
commitf664e2ec371f61b69e11147d7f9e045083335917
tree0e75793f8922cea2ffe64852dc62cda6bc0cdd88
parentcb3580e7ad247dfdcf2ad279895f52bb73c4cee4
Thread safety analysis: Always warn when dropping locks on back edges

We allow branches to join where one holds a managed lock but the other
doesn't, but we can't do so for back edges: because there we can't drop
them from the lockset, as we have already analyzed the loop with the
larger lockset. So we can't allow dropping managed locks on back edges.

We move the managed() check from handleRemovalFromIntersection up to
intersectAndWarn, where we additionally check if we're on a back edge if
we're removing from the first lock set (the entry set of the next block)
but not if we're removing from the second lock set (the exit set of the
previous block). Now that the order of arguments matters, I had to swap
them in one invocation, which also causes some minor differences in the
tests.

Reviewed By: delesley

Differential Revision: https://reviews.llvm.org/D104261
clang/lib/Analysis/ThreadSafety.cpp
clang/test/SemaCXX/warn-thread-safety-analysis.cpp