Skip to content

Commit a14396d

Browse files
committed
IntegerLiterals are no longer evaluated to create separate nodes; their
values are determined when evaluating the parent expression. llvm-svn: 46096
1 parent 493444f commit a14396d

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

clang/Analysis/GRConstants.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,19 @@ class VISIBILITY_HIDDEN GRConstants : public CFGStmtVisitor<GRConstants> {
204204
void BlockStmt_VisitStmt(Stmt* S) { DoStmt(S); }
205205

206206
void VisitAssign(BinaryOperator* O);
207-
void VisitIntegerLiteral(IntegerLiteral* L);
208207
void VisitBinAdd(BinaryOperator* O);
209208
void VisitBinSub(BinaryOperator* O);
210209
void VisitBinAssign(BinaryOperator* D);
211210
};
212211
} // end anonymous namespace
213212

213+
static inline Expr* IgnoreParen(Expr* E) {
214+
while (ParenExpr* P = dyn_cast<ParenExpr>(E))
215+
E = P->getSubExpr();
216+
217+
return E;
218+
}
219+
214220
void GRConstants::ProcessStmt(Stmt* S, NodeBuilder& builder) {
215221
Builder = &builder;
216222
Nodes->clear();
@@ -224,9 +230,20 @@ void GRConstants::ProcessStmt(Stmt* S, NodeBuilder& builder) {
224230

225231
ExprVariantTy GRConstants::GetBinding(Expr* E) {
226232
DSPtr P(NULL);
233+
E = IgnoreParen(E);
227234

228-
if (DeclRefExpr* D = dyn_cast<DeclRefExpr>(E)) P = DSPtr(D->getDecl());
229-
else P = DSPtr(E, getCFG().isBlkExpr(E));
235+
switch (E->getStmtClass()) {
236+
case Stmt::DeclRefExprClass:
237+
P = DSPtr(cast<DeclRefExpr>(E)->getDecl());
238+
break;
239+
240+
case Stmt::IntegerLiteralClass:
241+
return cast<IntegerLiteral>(E)->getValue().getZExtValue();
242+
243+
default:
244+
P = DSPtr(E, getCFG().isBlkExpr(E));
245+
break;
246+
}
230247

231248
StateTy::iterator I = CurrentState.find(P);
232249

@@ -297,10 +314,6 @@ void GRConstants::DoStmt(Stmt* S) {
297314
SwitchNodeSets();
298315
}
299316

300-
void GRConstants::VisitIntegerLiteral(IntegerLiteral* L) {
301-
AddBinding(L, L->getValue().getZExtValue());
302-
}
303-
304317
void GRConstants::VisitBinAdd(BinaryOperator* B) {
305318
AddBinding(B, GetBinding(B->getLHS()) + GetBinding(B->getRHS()));
306319
}
@@ -310,14 +323,6 @@ void GRConstants::VisitBinSub(BinaryOperator* B) {
310323
}
311324

312325

313-
static inline Expr* IgnoreParen(Expr* E) {
314-
while (ParenExpr* P = dyn_cast<ParenExpr>(E))
315-
E = P->getSubExpr();
316-
317-
return E;
318-
}
319-
320-
321326
void GRConstants::VisitBinAssign(BinaryOperator* B) {
322327
if (DeclRefExpr* D = dyn_cast<DeclRefExpr>(IgnoreParen(B->getLHS())))
323328
AddBinding(D->getDecl(), GetBinding(B->getRHS()));

0 commit comments

Comments
 (0)