From a14396d51dcab26c73e912b9ad6bf3d17a30759d Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 16 Jan 2008 22:28:08 +0000 Subject: [PATCH] IntegerLiterals are no longer evaluated to create separate nodes; their values are determined when evaluating the parent expression. llvm-svn: 46096 --- clang/Analysis/GRConstants.cpp | 35 +++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/clang/Analysis/GRConstants.cpp b/clang/Analysis/GRConstants.cpp index 2173f9b671b2..5acaf79b34ac 100644 --- a/clang/Analysis/GRConstants.cpp +++ b/clang/Analysis/GRConstants.cpp @@ -204,13 +204,19 @@ public: void BlockStmt_VisitStmt(Stmt* S) { DoStmt(S); } void VisitAssign(BinaryOperator* O); - void VisitIntegerLiteral(IntegerLiteral* L); void VisitBinAdd(BinaryOperator* O); void VisitBinSub(BinaryOperator* O); void VisitBinAssign(BinaryOperator* D); }; } // end anonymous namespace +static inline Expr* IgnoreParen(Expr* E) { + while (ParenExpr* P = dyn_cast(E)) + E = P->getSubExpr(); + + return E; +} + void GRConstants::ProcessStmt(Stmt* S, NodeBuilder& builder) { Builder = &builder; Nodes->clear(); @@ -224,9 +230,20 @@ void GRConstants::ProcessStmt(Stmt* S, NodeBuilder& builder) { ExprVariantTy GRConstants::GetBinding(Expr* E) { DSPtr P(NULL); + E = IgnoreParen(E); - if (DeclRefExpr* D = dyn_cast(E)) P = DSPtr(D->getDecl()); - else P = DSPtr(E, getCFG().isBlkExpr(E)); + switch (E->getStmtClass()) { + case Stmt::DeclRefExprClass: + P = DSPtr(cast(E)->getDecl()); + break; + + case Stmt::IntegerLiteralClass: + return cast(E)->getValue().getZExtValue(); + + default: + P = DSPtr(E, getCFG().isBlkExpr(E)); + break; + } StateTy::iterator I = CurrentState.find(P); @@ -297,10 +314,6 @@ void GRConstants::DoStmt(Stmt* S) { SwitchNodeSets(); } -void GRConstants::VisitIntegerLiteral(IntegerLiteral* L) { - AddBinding(L, L->getValue().getZExtValue()); -} - void GRConstants::VisitBinAdd(BinaryOperator* B) { AddBinding(B, GetBinding(B->getLHS()) + GetBinding(B->getRHS())); } @@ -310,14 +323,6 @@ void GRConstants::VisitBinSub(BinaryOperator* B) { } -static inline Expr* IgnoreParen(Expr* E) { - while (ParenExpr* P = dyn_cast(E)) - E = P->getSubExpr(); - - return E; -} - - void GRConstants::VisitBinAssign(BinaryOperator* B) { if (DeclRefExpr* D = dyn_cast(IgnoreParen(B->getLHS()))) AddBinding(D->getDecl(), GetBinding(B->getRHS()));