-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC] [analyzer] Factor out SymbolManager::get<*> #121781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This should generalize to all get<symbol> methods handled in subsequent commits
@NagyDonat Here is the refactoring you suggested in #121551 I made sure |
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm grateful for this code quality improvement, it's nice to see that you got rid of 180 lines of boilerplate 😄
I have one minor inline suggestion that it would be nice to document the purpose of this new template method; but otherwise the change is straightforward and clearly LGTM. (Assuming that the deleted methods are not called elsewhere, which you obviously checked.)
@@ -525,14 +527,14 @@ class SymbolManager { | |||
|
|||
static bool canSymbolicate(QualType T); | |||
|
|||
/// Make a unique symbol for MemRegion R according to its kind. | |||
const SymbolRegionValue* getRegionValueSymbol(const TypedValueRegion* R); | |||
template <typename T, typename... Args> const T *get(Args &&...args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If somebody reads this generic declaration without any context, they won't see any connection to symbols. Perhaps it would be good to either rename T
to something like SymbolType
or add a brief comment to describe the role of this method.
🤔 In fact, now that I write this, maybe it would be better to rename this method to "make
" or something similar to highlight that it's a factory method that makes new symbol objects (as opposed to e.g. ProgramState::get<>()
which queries an existing state trait object from the state).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If somebody reads this generic declaration without any context, they won't see any connection to symbols. Perhaps it would be good to either rename
T
to something likeSymbolType
or add a brief comment to describe the role of this method.
That makes sense. I'll do both once we agree on the next point
🤔 In fact, now that I write this, maybe it would be better to rename this method to "
make
" or something similar to highlight that it's a factory method that makes new symbol objects (as opposed to e.g.ProgramState::get<>()
which queries an existing state trait object from the state).
I was considering "make" briefly, but it is not entirely correct: this function doesn't always make a SymExpr
, sometimes it retrieves an existing one matching the arguments. Besides, most of the replaced member functions were called get*
. How do you like findOrCreate
, createIfNone
, ensureExists
, obtain
, acquire
, procure
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was considering "make" briefly, but it is not entirely correct: this function doesn't always make a
SymExpr
, sometimes it retrieves an existing one matching the arguments. Besides, most of the replaced member functions were calledget*
.
I would say that "make
" is still reasonable in this case, because semantically it makes the symbol which is determined by the arguments passed to it -- and it's just an implementation detail that symbols are immutable objects and the make
call returns already created symbols instead of recreating them. However, I can accept a different name if you're opposed to "make
".
How do you like
findOrCreate
,createIfNone
,ensureExists
,obtain
,acquire
,procure
?
I think acquire
would be the best choice among these, followed by something like makeOrGet
or findOrCreate
. IMO obtain
suggests that we're getting the symbol from an external source, procure
has unfortunate connections to sexual services and I don't like createIfNone
and ensureExists
because they don't imply that the method returns the symbol in addition to just initializing it in some internal table.
I still slightly prefer make
over acquire
(it's a shorter, more typical name for a factory method), but acquire
is close to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in
83b9302 [NFC] Rename and document acquire<SymExprT, ...>
member function
Following review suggestions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
@steakhal |
Sorry, I just noticed that I had broken formatting. Now it should be fixed |
@llvm/pr-subscribers-clang-static-analyzer-1 @llvm/pr-subscribers-clang Author: Arseniy Zaostrovnykh (necto) ChangesReplace the family of Patch is 21.72 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/121781.diff 7 Files Affected:
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
index c530dff495238b..b0d278687af933 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -113,10 +113,10 @@ class SymbolConjured : public SymbolData {
void dumpToStream(raw_ostream &os) const override;
- static void Profile(llvm::FoldingSetNodeID& profile, const Stmt *S,
- QualType T, unsigned Count, const LocationContext *LCtx,
+ static void Profile(llvm::FoldingSetNodeID &profile, const Stmt *S,
+ const LocationContext *LCtx, QualType T, unsigned Count,
const void *SymbolTag) {
- profile.AddInteger((unsigned) SymbolConjuredKind);
+ profile.AddInteger((unsigned)SymbolConjuredKind);
profile.AddPointer(S);
profile.AddPointer(LCtx);
profile.Add(T);
@@ -125,7 +125,7 @@ class SymbolConjured : public SymbolData {
}
void Profile(llvm::FoldingSetNodeID& profile) override {
- Profile(profile, S, T, Count, LCtx, SymbolTag);
+ Profile(profile, S, LCtx, T, Count, SymbolTag);
}
// Implement isa<T> support.
@@ -224,6 +224,8 @@ class SymbolMetadata : public SymbolData {
const Stmt *S;
QualType T;
const LocationContext *LCtx;
+ /// Count can be used to differentiate regions corresponding to
+ /// different loop iterations, thus, making the symbol path-dependent.
unsigned Count;
const void *Tag;
@@ -525,14 +527,18 @@ class SymbolManager {
static bool canSymbolicate(QualType T);
- /// Make a unique symbol for MemRegion R according to its kind.
- const SymbolRegionValue* getRegionValueSymbol(const TypedValueRegion* R);
+ /// Create or retrieve a SymExpr of type \p SymExprT for the given arguments.
+ /// Use the arguments to check for an existing SymExpr and return it,
+ /// otherwise, create a new one and keep a pointer to it to avoid duplicates.
+ template <typename SymExprT, typename... Args>
+ const SymExprT *acquire(Args &&...args);
- const SymbolConjured* conjureSymbol(const Stmt *E,
- const LocationContext *LCtx,
- QualType T,
+ const SymbolConjured *conjureSymbol(const Stmt *E,
+ const LocationContext *LCtx, QualType T,
unsigned VisitCount,
- const void *SymbolTag = nullptr);
+ const void *SymbolTag = nullptr) {
+ return acquire<SymbolConjured>(E, LCtx, T, VisitCount, SymbolTag);
+ }
const SymbolConjured* conjureSymbol(const Expr *E,
const LocationContext *LCtx,
@@ -541,41 +547,6 @@ class SymbolManager {
return conjureSymbol(E, LCtx, E->getType(), VisitCount, SymbolTag);
}
- const SymbolDerived *getDerivedSymbol(SymbolRef parentSymbol,
- const TypedValueRegion *R);
-
- const SymbolExtent *getExtentSymbol(const SubRegion *R);
-
- /// Creates a metadata symbol associated with a specific region.
- ///
- /// VisitCount can be used to differentiate regions corresponding to
- /// different loop iterations, thus, making the symbol path-dependent.
- const SymbolMetadata *getMetadataSymbol(const MemRegion *R, const Stmt *S,
- QualType T,
- const LocationContext *LCtx,
- unsigned VisitCount,
- const void *SymbolTag = nullptr);
-
- const SymbolCast* getCastSymbol(const SymExpr *Operand,
- QualType From, QualType To);
-
- const SymIntExpr *getSymIntExpr(const SymExpr *lhs, BinaryOperator::Opcode op,
- APSIntPtr rhs, QualType t);
-
- const SymIntExpr *getSymIntExpr(const SymExpr &lhs, BinaryOperator::Opcode op,
- APSIntPtr rhs, QualType t) {
- return getSymIntExpr(&lhs, op, rhs, t);
- }
-
- const IntSymExpr *getIntSymExpr(APSIntPtr lhs, BinaryOperator::Opcode op,
- const SymExpr *rhs, QualType t);
-
- const SymSymExpr *getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op,
- const SymExpr *rhs, QualType t);
-
- const UnarySymExpr *getUnarySymExpr(const SymExpr *operand,
- UnaryOperator::Opcode op, QualType t);
-
QualType getType(const SymExpr *SE) const {
return SE->getType();
}
@@ -707,6 +678,19 @@ class SymbolVisitor {
virtual bool VisitMemRegion(const MemRegion *) { return true; }
};
+template <typename T, typename... Args>
+const T *SymbolManager::acquire(Args &&...args) {
+ llvm::FoldingSetNodeID profile;
+ T::Profile(profile, std::forward<Args>(args)...);
+ void *InsertPos;
+ SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
+ if (!SD) {
+ SD = Alloc.make<T>(std::forward<Args>(args)...);
+ DataSet.InsertNode(SD, InsertPos);
+ }
+ return cast<T>(SD);
+}
+
} // namespace ento
} // namespace clang
diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
index 559c80634c12e5..2c5cd2cf7630f6 100644
--- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -811,7 +811,7 @@ DefinedOrUnknownSVal MemRegionManager::getStaticSize(const MemRegion *MR,
switch (SR->getKind()) {
case MemRegion::AllocaRegionKind:
case MemRegion::SymbolicRegionKind:
- return nonloc::SymbolVal(SymMgr.getExtentSymbol(SR));
+ return nonloc::SymbolVal(SymMgr.acquire<SymbolExtent>(SR));
case MemRegion::StringRegionKind:
return SVB.makeIntVal(
cast<StringRegion>(SR)->getStringLiteral()->getByteLength() + 1,
@@ -829,7 +829,7 @@ DefinedOrUnknownSVal MemRegionManager::getStaticSize(const MemRegion *MR,
case MemRegion::ObjCStringRegionKind: {
QualType Ty = cast<TypedValueRegion>(SR)->getDesugaredValueType(Ctx);
if (isa<VariableArrayType>(Ty))
- return nonloc::SymbolVal(SymMgr.getExtentSymbol(SR));
+ return nonloc::SymbolVal(SymMgr.acquire<SymbolExtent>(SR));
if (Ty->isIncompleteType())
return UnknownVal();
@@ -897,7 +897,7 @@ DefinedOrUnknownSVal MemRegionManager::getStaticSize(const MemRegion *MR,
case MemRegion::BlockDataRegionKind:
case MemRegion::BlockCodeRegionKind:
case MemRegion::FunctionCodeRegionKind:
- return nonloc::SymbolVal(SymMgr.getExtentSymbol(SR));
+ return nonloc::SymbolVal(SymMgr.acquire<SymbolExtent>(SR));
default:
llvm_unreachable("Unhandled region");
}
diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index c39fa81109c853..ab45e678bafd53 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -1471,7 +1471,7 @@ class SymbolicRangeInferrer
return getRangeForNegatedExpr(
[SSE, State = this->State]() -> SymbolRef {
if (SSE->getOpcode() == BO_Sub)
- return State->getSymbolManager().getSymSymExpr(
+ return State->getSymbolManager().acquire<SymSymExpr>(
SSE->getRHS(), BO_Sub, SSE->getLHS(), SSE->getType());
return nullptr;
},
@@ -1481,8 +1481,8 @@ class SymbolicRangeInferrer
std::optional<RangeSet> getRangeForNegatedSym(SymbolRef Sym) {
return getRangeForNegatedExpr(
[Sym, State = this->State]() {
- return State->getSymbolManager().getUnarySymExpr(Sym, UO_Minus,
- Sym->getType());
+ return State->getSymbolManager().acquire<UnarySymExpr>(
+ Sym, UO_Minus, Sym->getType());
},
Sym->getType());
}
@@ -1495,7 +1495,7 @@ class SymbolicRangeInferrer
if (!IsCommutative)
return std::nullopt;
- SymbolRef Commuted = State->getSymbolManager().getSymSymExpr(
+ SymbolRef Commuted = State->getSymbolManager().acquire<SymSymExpr>(
SSE->getRHS(), Op, SSE->getLHS(), SSE->getType());
if (const RangeSet *Range = getConstraint(State, Commuted))
return *Range;
@@ -1540,7 +1540,8 @@ class SymbolicRangeInferrer
// Let's find an expression e.g. (x < y).
BinaryOperatorKind QueriedOP = OperatorRelationsTable::getOpFromIndex(i);
- const SymSymExpr *SymSym = SymMgr.getSymSymExpr(LHS, QueriedOP, RHS, T);
+ const SymSymExpr *SymSym =
+ SymMgr.acquire<SymSymExpr>(LHS, QueriedOP, RHS, T);
const RangeSet *QueriedRangeSet = getConstraint(State, SymSym);
// If ranges were not previously found,
@@ -1548,7 +1549,7 @@ class SymbolicRangeInferrer
if (!QueriedRangeSet) {
const BinaryOperatorKind ROP =
BinaryOperator::reverseComparisonOp(QueriedOP);
- SymSym = SymMgr.getSymSymExpr(RHS, ROP, LHS, T);
+ SymSym = SymMgr.acquire<SymSymExpr>(RHS, ROP, LHS, T);
QueriedRangeSet = getConstraint(State, SymSym);
}
diff --git a/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp b/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
index 4bbe933be2129e..94dcdaf3276896 100644
--- a/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
@@ -62,8 +62,8 @@ ProgramStateRef RangedConstraintManager::assumeSym(ProgramStateRef State,
SymbolManager &SymMgr = getSymbolManager();
QualType DiffTy = SymMgr.getContext().getPointerDiffType();
- SymbolRef Subtraction =
- SymMgr.getSymSymExpr(SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
+ SymbolRef Subtraction = SymMgr.acquire<SymSymExpr>(
+ SSE->getRHS(), BO_Sub, SSE->getLHS(), DiffTy);
const llvm::APSInt &Zero = getBasicVals().getValue(0, DiffTy);
Op = BinaryOperator::reverseComparisonOp(Op);
@@ -76,8 +76,8 @@ ProgramStateRef RangedConstraintManager::assumeSym(ProgramStateRef State,
SymbolManager &SymMgr = getSymbolManager();
QualType ExprType = SSE->getType();
- SymbolRef CanonicalEquality =
- SymMgr.getSymSymExpr(SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
+ SymbolRef CanonicalEquality = SymMgr.acquire<SymSymExpr>(
+ SSE->getLHS(), BO_EQ, SSE->getRHS(), ExprType);
bool WasEqual = SSE->getOpcode() == BO_EQ;
bool IsExpectedEqual = WasEqual == Assumption;
diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
index 2b855801863818..4f45b24be86c1d 100644
--- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -79,7 +79,7 @@ nonloc::SymbolVal SValBuilder::makeNonLoc(const SymExpr *lhs,
APSIntPtr rhs, QualType type) {
assert(lhs);
assert(!Loc::isLocType(type));
- return nonloc::SymbolVal(SymMgr.getSymIntExpr(lhs, op, rhs, type));
+ return nonloc::SymbolVal(SymMgr.acquire<SymIntExpr>(lhs, op, rhs, type));
}
nonloc::SymbolVal SValBuilder::makeNonLoc(APSIntPtr lhs,
@@ -87,7 +87,7 @@ nonloc::SymbolVal SValBuilder::makeNonLoc(APSIntPtr lhs,
const SymExpr *rhs, QualType type) {
assert(rhs);
assert(!Loc::isLocType(type));
- return nonloc::SymbolVal(SymMgr.getIntSymExpr(lhs, op, rhs, type));
+ return nonloc::SymbolVal(SymMgr.acquire<IntSymExpr>(lhs, op, rhs, type));
}
nonloc::SymbolVal SValBuilder::makeNonLoc(const SymExpr *lhs,
@@ -95,14 +95,14 @@ nonloc::SymbolVal SValBuilder::makeNonLoc(const SymExpr *lhs,
const SymExpr *rhs, QualType type) {
assert(lhs && rhs);
assert(!Loc::isLocType(type));
- return nonloc::SymbolVal(SymMgr.getSymSymExpr(lhs, op, rhs, type));
+ return nonloc::SymbolVal(SymMgr.acquire<SymSymExpr>(lhs, op, rhs, type));
}
NonLoc SValBuilder::makeNonLoc(const SymExpr *operand, UnaryOperator::Opcode op,
QualType type) {
assert(operand);
assert(!Loc::isLocType(type));
- return nonloc::SymbolVal(SymMgr.getUnarySymExpr(operand, op, type));
+ return nonloc::SymbolVal(SymMgr.acquire<UnarySymExpr>(operand, op, type));
}
nonloc::SymbolVal SValBuilder::makeNonLoc(const SymExpr *operand,
@@ -111,7 +111,7 @@ nonloc::SymbolVal SValBuilder::makeNonLoc(const SymExpr *operand,
assert(!Loc::isLocType(toTy));
if (fromTy == toTy)
return nonloc::SymbolVal(operand);
- return nonloc::SymbolVal(SymMgr.getCastSymbol(operand, fromTy, toTy));
+ return nonloc::SymbolVal(SymMgr.acquire<SymbolCast>(operand, fromTy, toTy));
}
SVal SValBuilder::convertToArrayIndex(SVal val) {
@@ -143,7 +143,7 @@ SValBuilder::getRegionValueSymbolVal(const TypedValueRegion *region) {
if (!SymbolManager::canSymbolicate(T))
return UnknownVal();
- SymbolRef sym = SymMgr.getRegionValueSymbol(region);
+ SymbolRef sym = SymMgr.acquire<SymbolRegionValue>(region);
if (Loc::isLocType(T))
return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
@@ -244,8 +244,8 @@ DefinedSVal SValBuilder::getMetadataSymbolVal(const void *symbolTag,
unsigned count) {
assert(SymbolManager::canSymbolicate(type) && "Invalid metadata symbol type");
- SymbolRef sym =
- SymMgr.getMetadataSymbol(region, expr, type, LCtx, count, symbolTag);
+ SymbolRef sym = SymMgr.acquire<SymbolMetadata>(region, expr, type, LCtx,
+ count, symbolTag);
if (Loc::isLocType(type))
return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
@@ -264,7 +264,7 @@ SValBuilder::getDerivedRegionValueSymbolVal(SymbolRef parentSymbol,
if (!SymbolManager::canSymbolicate(T))
return UnknownVal();
- SymbolRef sym = SymMgr.getDerivedSymbol(parentSymbol, region);
+ SymbolRef sym = SymMgr.acquire<SymbolDerived>(parentSymbol, region);
if (Loc::isLocType(T))
return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
@@ -724,7 +724,7 @@ class EvalCastVisitor : public SValVisitor<EvalCastVisitor, SVal> {
// because there are no generic region address metadata
// symbols to use, only content metadata.
return nonloc::SymbolVal(
- VB.getSymbolManager().getExtentSymbol(FTR));
+ VB.getSymbolManager().acquire<SymbolExtent>(FTR));
if (const SymbolicRegion *SymR = R->getSymbolicBase()) {
SymbolRef Sym = SymR->getSymbol();
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 455621739f6935..afb0273d23bd45 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -328,16 +328,16 @@ static NonLoc doRearrangeUnchecked(ProgramStateRef State,
// FIXME: Maybe it'd be better to have consistency in
// "$x - $y" vs. "$y - $x" because those are solver's keys.
if (LInt > RInt) {
- ResultSym = SymMgr.getSymSymExpr(RSym, BO_Sub, LSym, SymTy);
+ ResultSym = SymMgr.acquire<SymSymExpr>(RSym, BO_Sub, LSym, SymTy);
ResultOp = BinaryOperator::reverseComparisonOp(Op);
ResultInt = LInt - RInt; // Opposite order!
} else {
- ResultSym = SymMgr.getSymSymExpr(LSym, BO_Sub, RSym, SymTy);
+ ResultSym = SymMgr.acquire<SymSymExpr>(LSym, BO_Sub, RSym, SymTy);
ResultOp = Op;
ResultInt = RInt - LInt; // Opposite order!
}
} else {
- ResultSym = SymMgr.getSymSymExpr(LSym, Op, RSym, SymTy);
+ ResultSym = SymMgr.acquire<SymSymExpr>(LSym, Op, RSym, SymTy);
ResultInt = (Op == BO_Add) ? (LInt + RInt) : (LInt - RInt);
ResultOp = BO_Add;
// Bring back the cosmetic difference.
@@ -350,8 +350,8 @@ static NonLoc doRearrangeUnchecked(ProgramStateRef State,
}
}
APSIntPtr PersistentResultInt = BV.getValue(ResultInt);
- return nonloc::SymbolVal(
- SymMgr.getSymIntExpr(ResultSym, ResultOp, PersistentResultInt, ResultTy));
+ return nonloc::SymbolVal(SymMgr.acquire<SymIntExpr>(
+ ResultSym, ResultOp, PersistentResultInt, ResultTy));
}
// Rearrange if symbol type matches the result type and if the operator is a
diff --git a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
index 738b6a175ce6de..a4648f5922ef11 100644
--- a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
@@ -163,161 +163,6 @@ void SymExpr::symbol_iterator::expand() {
llvm_unreachable("unhandled expansion case");
}
-const SymbolRegionValue*
-SymbolManager::getRegionValueSymbol(const TypedValueRegion* R) {
- llvm::FoldingSetNodeID profile;
- SymbolRegionValue::Profile(profile, R);
- void *InsertPos;
- SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
- if (!SD) {
- SD = Alloc.make<SymbolRegionValue>(R);
- DataSet.InsertNode(SD, InsertPos);
- }
-
- return cast<SymbolRegionValue>(SD);
-}
-
-const SymbolConjured* SymbolManager::conjureSymbol(const Stmt *E,
- const LocationContext *LCtx,
- QualType T,
- unsigned Count,
- const void *SymbolTag) {
- llvm::FoldingSetNodeID profile;
- SymbolConjured::Profile(profile, E, T, Count, LCtx, SymbolTag);
- void *InsertPos;
- SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
- if (!SD) {
- SD = Alloc.make<SymbolConjured>(E, LCtx, T, Count, SymbolTag);
- DataSet.InsertNode(SD, InsertPos);
- }
-
- return cast<SymbolConjured>(SD);
-}
-
-const SymbolDerived*
-SymbolManager::getDerivedSymbol(SymbolRef parentSymbol,
- const TypedValueRegion *R) {
- llvm::FoldingSetNodeID profile;
- SymbolDerived::Profile(profile, parentSymbol, R);
- void *InsertPos;
- SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
- if (!SD) {
- SD = Alloc.make<SymbolDerived>(parentSymbol, R);
- DataSet.InsertNode(SD, InsertPos);
- }
-
- return cast<SymbolDerived>(SD);
-}
-
-const SymbolExtent*
-SymbolManager::getExtentSymbol(const SubRegion *R) {
- llvm::FoldingSetNodeID profile;
- SymbolExtent::Profile(profile, R);
- void *InsertPos;
- SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
- if (!SD) {
- SD = Alloc.make<SymbolExtent>(R);
- DataSet.InsertNode(SD, InsertPos);
- }
-
- return cast<SymbolExtent>(SD);
-}
-
-const SymbolMetadata *
-SymbolManager::getMetadataSymbol(const MemRegion* R, const Stmt *S, QualType T,
- const LocationContext *LCtx,
- unsigned Count, const void *SymbolTag) {
- llvm::FoldingSetNodeID profile;
- SymbolMetadata::Profile(profile, R, S, T, LCtx, Count, SymbolTag);
- void *InsertPos;
- SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
- if (!SD) {
- SD = Alloc.make<SymbolMetadata>(R, S, T, LCtx, Count, SymbolTag);
- DataSet.InsertNode(SD, InsertPos);
- }
-
- return cast<SymbolMetadata>(SD);
-}
-
-const SymbolCast*
-SymbolManager::getCastSymbol(const SymExpr *Op,
- QualType From, QualType To) {
- llvm::FoldingSetNodeID ID;
- SymbolCast::Profile(ID, Op, From, To);
- void *InsertPos;
- SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
- if (!data) {
- data = Alloc.make<SymbolCast>(Op, From, To);
- DataSet.InsertNode(data, InsertPos);
- }
-
- return cast<SymbolCast>(data);
-}
-
-const SymIntExpr *SymbolManager::getSymIntExpr(const SymExpr *lhs,
- BinaryOperator::Opcode op,
- APSIntPtr v, QualType t) {
- llvm::FoldingSetNodeID ID;
- SymIntExpr::Profile(ID, lhs, op, v, t);
- void *InsertPos;
- SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos);
-
- if (!data) {
- data = Alloc.make<SymIntExpr>(lhs, op, v, t);
- DataSet.InsertNode(data, InsertPos);
- }
-
- return c...
[truncated]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the first time I'm seeing this. I took the liberty to also review it.
Looks pretty good. I have a few nits though.
I'll fix them and merge the PR.
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
Outdated
Show resolved
Hide resolved
Replace the family of `SymbolManager::get*Symbol(...)` member functions with a single generic `SymbolManager::get<*>` member function.
Replace the family of
SymbolManager::get*Symbol(...)
member functions with a single genericSymbolManager::get<*>
member function.