Skip to content

Commit a5defd2

Browse files
committed
Thread Safety Analysis: Convert CapabilityExpr::CapExpr to hold flags
Rather than holding a single bool, switch it to contain flags, which is both more descriptive and simplifies adding more flags in subsequent changes. NFC.
1 parent 9a1bfc1 commit a5defd2

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,26 +271,28 @@ class CFGWalker {
271271
// translateAttrExpr needs it, but that should be moved too.
272272
class CapabilityExpr {
273273
private:
274-
/// The capability expression and whether it's negated.
275-
llvm::PointerIntPair<const til::SExpr *, 1, bool> CapExpr;
274+
static constexpr unsigned FlagNegative = 1u << 0;
275+
276+
/// The capability expression and flags.
277+
llvm::PointerIntPair<const til::SExpr *, 1, unsigned> CapExpr;
276278

277279
/// The kind of capability as specified by @ref CapabilityAttr::getName.
278280
StringRef CapKind;
279281

280282
public:
281-
CapabilityExpr() : CapExpr(nullptr, false) {}
283+
CapabilityExpr() : CapExpr(nullptr, 0) {}
282284
CapabilityExpr(const til::SExpr *E, StringRef Kind, bool Neg)
283-
: CapExpr(E, Neg), CapKind(Kind) {}
285+
: CapExpr(E, Neg ? FlagNegative : 0), CapKind(Kind) {}
284286

285287
// Don't allow implicitly-constructed StringRefs since we'll capture them.
286288
template <typename T> CapabilityExpr(const til::SExpr *, T, bool) = delete;
287289

288290
const til::SExpr *sexpr() const { return CapExpr.getPointer(); }
289291
StringRef getKind() const { return CapKind; }
290-
bool negative() const { return CapExpr.getInt(); }
292+
bool negative() const { return CapExpr.getInt() & FlagNegative; }
291293

292294
CapabilityExpr operator!() const {
293-
return CapabilityExpr(CapExpr.getPointer(), CapKind, !CapExpr.getInt());
295+
return CapabilityExpr(CapExpr.getPointer(), CapKind, !negative());
294296
}
295297

296298
bool equals(const CapabilityExpr &other) const {

0 commit comments

Comments
 (0)