From 2f868c013935791c421def45b422a6f6e79d2e4a Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 16 Apr 2008 02:59:55 +0000 Subject: [PATCH] Simplify some code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49763 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/UninitializedValues.cpp | 59 +++++++++++++--------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp index 74426e2296..d81a087fe0 100644 --- a/lib/Analysis/UninitializedValues.cpp +++ b/lib/Analysis/UninitializedValues.cpp @@ -79,50 +79,47 @@ public: bool BlockStmt_VisitExpr(Expr* E); void VisitTerminator(Stmt* T) { } - - VarDecl* FindBlockVarDecl(Stmt* S); }; static const bool Initialized = true; static const bool Uninitialized = false; bool TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) { - // FIXME: Ted, can this be simplified? - VarDecl* VD = dyn_cast(DR->getDecl()); - if (VD && VD->isBlockVarDecl()) { - if (AD.Observer) AD.Observer->ObserveDeclRefExpr(V,AD,DR,VD); + + if (VarDecl* VD = dyn_cast(DR->getDecl())) + if (VD->isBlockVarDecl()) { + + if (AD.Observer) + AD.Observer->ObserveDeclRefExpr(V, AD, DR, VD); - // Pseudo-hack to prevent cascade of warnings. If an accessed variable - // is uninitialized, then we are already going to flag a warning for - // this variable, which a "source" of uninitialized values. - // We can otherwise do a full "taint" of uninitialized values. The - // client has both options by toggling AD.FullUninitTaint. + // Pseudo-hack to prevent cascade of warnings. If an accessed variable + // is uninitialized, then we are already going to flag a warning for + // this variable, which a "source" of uninitialized values. + // We can otherwise do a full "taint" of uninitialized values. The + // client has both options by toggling AD.FullUninitTaint. - return AD.FullUninitTaint ? V(VD,AD) : Initialized; - } - else return Initialized; + if (AD.FullUninitTaint) + return V(VD,AD); + } + + return Initialized; } -VarDecl* TransferFuncs::FindBlockVarDecl(Stmt *S) { - for (;;) - if (ParenExpr* P = dyn_cast(S)) { - S = P->getSubExpr(); continue; - } - else if (DeclRefExpr* DR = dyn_cast(S)) { - // FIXME: Ted, can this be simplified? - VarDecl* VD = dyn_cast(DR->getDecl()); - if (VD->isBlockVarDecl()) - return VD; - else - return NULL; - } - else return NULL; +static VarDecl* FindBlockVarDecl(Expr* E) { + + // Blast through casts and parentheses to find any DeclRefExprs that + // refer to a block VarDecl. + + if (DeclRefExpr* DR = dyn_cast(E->IgnoreParenCasts())) + if (VarDecl* VD = dyn_cast(DR->getDecl())) + if (VD->isBlockVarDecl()) return VD; + + return NULL; } bool TransferFuncs::VisitBinaryOperator(BinaryOperator* B) { - // FIXME: Ted, can this be simplified? - VarDecl* VD = FindBlockVarDecl(B->getLHS()); - if (VD && VD->isBlockVarDecl()) + + if (VarDecl* VD = FindBlockVarDecl(B->getLHS())) if (B->isAssignmentOp()) { if (B->getOpcode() == BinaryOperator::Assign) return V(VD,AD) = Visit(B->getRHS()); -- 2.40.0