Skip to content

Commit ab541b0

Browse files
committed
refactor visitors to use common helper
1 parent 933e590 commit ab541b0

File tree

4 files changed

+44
-59
lines changed

4 files changed

+44
-59
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,6 @@ class ExprEngine {
499499
void VisitGuardedExpr(const Expr *Ex, const Expr *L, const Expr *R,
500500
ExplodedNode *Pred, ExplodedNodeSet &Dst);
501501

502-
void VisitInitListExpr(const InitListExpr *E, ExplodedNode *Pred,
503-
ExplodedNodeSet &Dst);
504-
505502
/// VisitAttributedStmt - Transfer function logic for AttributedStmt.
506503
void VisitAttributedStmt(const AttributedStmt *A, ExplodedNode *Pred,
507504
ExplodedNodeSet &Dst);
@@ -586,17 +583,14 @@ class ExprEngine {
586583
void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE, ExplodedNode *Pred,
587584
ExplodedNodeSet &Dst);
588585

589-
void VisitCXXParenListInitExpr(const CXXParenListInitExpr *PLIE,
590-
ExplodedNode *Pred, ExplodedNodeSet &Dst);
591-
592586
/// Create a C++ temporary object for an rvalue.
593587
void CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME,
594588
ExplodedNode *Pred,
595589
ExplodedNodeSet &Dst);
596590

597-
void CreateInitializationList(const Expr *Source, ArrayRef<Expr *> Args,
598-
bool IsTransparent, ExplodedNode *Pred,
599-
ExplodedNodeSet &Dst);
591+
void ConstructInitList(const Expr *Source, ArrayRef<Expr *> Args,
592+
bool IsTransparent, ExplodedNode *Pred,
593+
ExplodedNodeSet &Dst);
600594

601595
/// evalEagerlyAssumeBifurcation - Given the nodes in 'Src', eagerly assume
602596
/// concrete boolean values for 'Ex', storing the resulting nodes in 'Dst'.

clang/lib/StaticAnalyzer/Core/ExprEngine.cpp

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,17 +2314,22 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
23142314
break;
23152315
}
23162316

2317-
case Stmt::InitListExprClass:
2317+
case Stmt::InitListExprClass: {
2318+
const InitListExpr *E = cast<InitListExpr>(S);
23182319
Bldr.takeNodes(Pred);
2319-
VisitInitListExpr(cast<InitListExpr>(S), Pred, Dst);
2320+
ConstructInitList(E, E->inits(), E->isTransparent(), Pred, Dst);
23202321
Bldr.addNodes(Dst);
23212322
break;
2323+
}
23222324

2323-
case Expr::CXXParenListInitExprClass:
2325+
case Expr::CXXParenListInitExprClass: {
2326+
const CXXParenListInitExpr *E = cast<CXXParenListInitExpr>(S);
23242327
Bldr.takeNodes(Pred);
2325-
VisitCXXParenListInitExpr(cast<CXXParenListInitExpr>(S), Pred, Dst);
2328+
ConstructInitList(E, E->getInitExprs(), /*IsTransparent*/ false, Pred,
2329+
Dst);
23262330
Bldr.addNodes(Dst);
23272331
break;
2332+
}
23282333

23292334
case Stmt::MemberExprClass:
23302335
Bldr.takeNodes(Pred);
@@ -4119,3 +4124,35 @@ void *ProgramStateTrait<ReplayWithoutInlining>::GDMIndex() {
41194124
}
41204125

41214126
void ExprEngine::anchor() { }
4127+
4128+
void ExprEngine::ConstructInitList(const Expr *E, ArrayRef<Expr *> Args,
4129+
bool IsTransparent, ExplodedNode *Pred,
4130+
ExplodedNodeSet &Dst) {
4131+
assert((isa<InitListExpr>(E) || isa<CXXParenListInitExpr>(E)) &&
4132+
"Expected InitListExpr or CXXParenListInitExpr");
4133+
4134+
const LocationContext *LC = Pred->getLocationContext();
4135+
4136+
StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
4137+
ProgramStateRef S = Pred->getState();
4138+
QualType T = E->getType().getCanonicalType();
4139+
4140+
bool IsCompound =
4141+
E->isPRValue() && (T->isArrayType() || T->isRecordType() ||
4142+
T->isAnyComplexType() || T->isVectorType());
4143+
4144+
if (Args.size() > 1 || (IsCompound && !IsTransparent)) {
4145+
llvm::ImmutableList<SVal> ArgList = getBasicVals().getEmptySValList();
4146+
for (Expr *E : llvm::reverse(Args))
4147+
ArgList = getBasicVals().prependSVal(S->getSVal(E, LC), ArgList);
4148+
4149+
B.generateNode(E, Pred,
4150+
S->BindExpr(E, LC, svalBuilder.makeCompoundVal(T, ArgList)));
4151+
} else {
4152+
B.generateNode(E, Pred,
4153+
S->BindExpr(E, LC,
4154+
Args.size() == 0
4155+
? getSValBuilder().makeZeroVal(T)
4156+
: S->getSVal(Args.front(), LC)));
4157+
}
4158+
}

clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -771,12 +771,6 @@ void ExprEngine::VisitLogicalExpr(const BinaryOperator* B, ExplodedNode *Pred,
771771
Bldr.generateNode(B, Pred, state->BindExpr(B, Pred->getLocationContext(), X));
772772
}
773773

774-
void ExprEngine::VisitInitListExpr(const InitListExpr *IE,
775-
ExplodedNode *Pred,
776-
ExplodedNodeSet &Dst) {
777-
CreateInitializationList(IE, IE->inits(), IE->isTransparent(), Pred, Dst);
778-
}
779-
780774
void ExprEngine::VisitGuardedExpr(const Expr *Ex,
781775
const Expr *L,
782776
const Expr *R,
@@ -1155,36 +1149,3 @@ void ExprEngine::VisitIncrementDecrementOperator(const UnaryOperator* U,
11551149
}
11561150
Dst.insert(Dst2);
11571151
}
1158-
1159-
void ExprEngine::CreateInitializationList(const Expr *E, ArrayRef<Expr *> Args,
1160-
bool IsTransparent,
1161-
ExplodedNode *Pred,
1162-
ExplodedNodeSet &Dst) {
1163-
assert((isa<InitListExpr>(E) || isa<CXXParenListInitExpr>(E)) &&
1164-
"Expected InitListExpr or CXXParenListInitExpr");
1165-
1166-
const LocationContext *LC = Pred->getLocationContext();
1167-
1168-
StmtNodeBuilder B(Pred, Dst, *currBldrCtx);
1169-
ProgramStateRef S = Pred->getState();
1170-
QualType T = E->getType().getCanonicalType();
1171-
1172-
bool IsCompound =
1173-
E->isPRValue() && (T->isArrayType() || T->isRecordType() ||
1174-
T->isAnyComplexType() || T->isVectorType());
1175-
1176-
if (Args.size() > 1 || (IsCompound && !IsTransparent)) {
1177-
llvm::ImmutableList<SVal> ArgList = getBasicVals().getEmptySValList();
1178-
for (Expr *E : llvm::reverse(Args))
1179-
ArgList = getBasicVals().prependSVal(S->getSVal(E, LC), ArgList);
1180-
1181-
B.generateNode(E, Pred,
1182-
S->BindExpr(E, LC, svalBuilder.makeCompoundVal(T, ArgList)));
1183-
} else {
1184-
B.generateNode(E, Pred,
1185-
S->BindExpr(E, LC,
1186-
Args.size() == 0
1187-
? getSValBuilder().makeZeroVal(T)
1188-
: S->getSVal(Args.front(), LC)));
1189-
}
1190-
}

clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,10 +1233,3 @@ void ExprEngine::VisitAttributedStmt(const AttributedStmt *A,
12331233

12341234
getCheckerManager().runCheckersForPostStmt(Dst, EvalSet, A, *this);
12351235
}
1236-
1237-
void ExprEngine::VisitCXXParenListInitExpr(const CXXParenListInitExpr *E,
1238-
ExplodedNode *Pred,
1239-
ExplodedNodeSet &Dst) {
1240-
CreateInitializationList(E, E->getInitExprs(), /*IsTransparent*/ false, Pred,
1241-
Dst);
1242-
}

0 commit comments

Comments
 (0)