Skip to content

Commit dd1790c

Browse files
committed
Thread safety analysis: Pack CapabilityExpr using PointerIntPair (NFC)
We're storing these quite frequently: FactEntry inherits from CapabilityExpr, and the FactManager has a vector of such entries. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D124127
1 parent 5227be8 commit dd1790c

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "clang/Analysis/CFG.h"
3131
#include "clang/Basic/LLVM.h"
3232
#include "llvm/ADT/DenseMap.h"
33+
#include "llvm/ADT/PointerIntPair.h"
3334
#include "llvm/ADT/SmallVector.h"
3435
#include "llvm/Support/Casting.h"
3536
#include <sstream>
@@ -269,56 +270,55 @@ class CFGWalker {
269270
// translateAttrExpr needs it, but that should be moved too.
270271
class CapabilityExpr {
271272
private:
272-
/// The capability expression.
273-
const til::SExpr* CapExpr;
274-
275-
/// True if this is a negative capability.
276-
bool Negated;
273+
/// The capability expression and whether it's negated.
274+
llvm::PointerIntPair<const til::SExpr *, 1, bool> CapExpr;
277275

278276
public:
279-
CapabilityExpr(const til::SExpr *E, bool Neg) : CapExpr(E), Negated(Neg) {}
277+
CapabilityExpr(const til::SExpr *E, bool Neg) : CapExpr(E, Neg) {}
280278

281-
const til::SExpr* sexpr() const { return CapExpr; }
282-
bool negative() const { return Negated; }
279+
const til::SExpr *sexpr() const { return CapExpr.getPointer(); }
280+
bool negative() const { return CapExpr.getInt(); }
283281

284282
CapabilityExpr operator!() const {
285-
return CapabilityExpr(CapExpr, !Negated);
283+
return CapabilityExpr(CapExpr.getPointer(), !CapExpr.getInt());
286284
}
287285

288286
bool equals(const CapabilityExpr &other) const {
289-
return (Negated == other.Negated) && sx::equals(CapExpr, other.CapExpr);
287+
return (negative() == other.negative()) &&
288+
sx::equals(sexpr(), other.sexpr());
290289
}
291290

292291
bool matches(const CapabilityExpr &other) const {
293-
return (Negated == other.Negated) && sx::matches(CapExpr, other.CapExpr);
292+
return (negative() == other.negative()) &&
293+
sx::matches(sexpr(), other.sexpr());
294294
}
295295

296296
bool matchesUniv(const CapabilityExpr &CapE) const {
297297
return isUniversal() || matches(CapE);
298298
}
299299

300300
bool partiallyMatches(const CapabilityExpr &other) const {
301-
return (Negated == other.Negated) &&
302-
sx::partiallyMatches(CapExpr, other.CapExpr);
301+
return (negative() == other.negative()) &&
302+
sx::partiallyMatches(sexpr(), other.sexpr());
303303
}
304304

305305
const ValueDecl* valueDecl() const {
306-
if (Negated || CapExpr == nullptr)
306+
if (negative() || sexpr() == nullptr)
307307
return nullptr;
308-
if (const auto *P = dyn_cast<til::Project>(CapExpr))
308+
if (const auto *P = dyn_cast<til::Project>(sexpr()))
309309
return P->clangDecl();
310-
if (const auto *P = dyn_cast<til::LiteralPtr>(CapExpr))
310+
if (const auto *P = dyn_cast<til::LiteralPtr>(sexpr()))
311311
return P->clangDecl();
312312
return nullptr;
313313
}
314314

315315
std::string toString() const {
316-
if (Negated)
317-
return "!" + sx::toString(CapExpr);
318-
return sx::toString(CapExpr);
316+
if (negative())
317+
return "!" + sx::toString(sexpr());
318+
return sx::toString(sexpr());
319319
}
320320

321-
bool shouldIgnore() const { return CapExpr == nullptr; }
321+
bool shouldIgnore() const { return sexpr() == nullptr; }
322322

323323
bool isInvalid() const { return sexpr() && isa<til::Undefined>(sexpr()); }
324324

0 commit comments

Comments
 (0)