Skip to content

Commit f8afb8f

Browse files
committed
Thread safety analysis: Store capability kind in CapabilityExpr
This should make us print the right capability kind in many more cases, especially when attributes name multiple capabilities of different kinds. Previously we were trying to deduce the capability kind from the original attribute, but most attributes can name multiple capabilities, which could be of different kinds. So instead we derive the kind when translating the attribute expression, and then store it in the returned CapabilityExpr. Then we can extract the corresponding capability name when we need it, which saves us lots of plumbing and almost guarantees that the name is right. I didn't bother adding any tests for this because it's just a usability improvement and it's pretty much evident from the code that we don't fall back to "mutex" anymore (save for a few cases that I'll address in a separate change). Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D124131
1 parent d65c922 commit f8afb8f

File tree

4 files changed

+126
-170
lines changed

4 files changed

+126
-170
lines changed

clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,23 @@ class CapabilityExpr {
273273
/// The capability expression and whether it's negated.
274274
llvm::PointerIntPair<const til::SExpr *, 1, bool> CapExpr;
275275

276+
/// The kind of capability as specified by @ref CapabilityAttr::getName.
277+
StringRef CapKind;
278+
276279
public:
277-
CapabilityExpr(const til::SExpr *E, bool Neg) : CapExpr(E, Neg) {}
280+
CapabilityExpr() : CapExpr(nullptr, false) {}
281+
CapabilityExpr(const til::SExpr *E, StringRef Kind, bool Neg)
282+
: CapExpr(E, Neg), CapKind(Kind) {}
283+
284+
// Don't allow implicitly-constructed StringRefs since we'll capture them.
285+
template <typename T> CapabilityExpr(const til::SExpr *, T, bool) = delete;
278286

279287
const til::SExpr *sexpr() const { return CapExpr.getPointer(); }
288+
StringRef getKind() const { return CapKind; }
280289
bool negative() const { return CapExpr.getInt(); }
281290

282291
CapabilityExpr operator!() const {
283-
return CapabilityExpr(CapExpr.getPointer(), !CapExpr.getInt());
292+
return CapabilityExpr(CapExpr.getPointer(), CapKind, !CapExpr.getInt());
284293
}
285294

286295
bool equals(const CapabilityExpr &other) const {

0 commit comments

Comments
 (0)