Hi Zhongxing, Is the "default" case need? I'd rather just enumerate all the cases and start with reasonable default behavior than have a default case with an assertion (which would be caught at runtime with a crash instead of at compile time).
Ted On Jan 21, 2010, at 8:30 PM, Zhongxing Xu wrote: > Author: zhongxingxu > Date: Thu Jan 21 22:30:00 2010 > New Revision: 94153 > > URL: http://llvm.org/viewvc/llvm-project?rev=94153&view=rev > Log: > Process cast according to the cast kind. Prepare for more specific cast > handling (for C++). No functionality change for now. > > Modified: > cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h > cfe/trunk/lib/Analysis/GRExprEngine.cpp > > Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h?rev=94153&r1=94152&r2=94153&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h (original) > +++ cfe/trunk/include/clang/Analysis/PathSensitive/GRExprEngine.h Thu Jan 21 > 22:30:00 2010 > @@ -270,8 +270,8 @@ > ExplodedNodeSet& Dst, bool asLValue); > > /// VisitCast - Transfer function logic for all casts (implicit and > explicit). > - void VisitCast(Expr* CastE, Expr* Ex, ExplodedNode* Pred, > - ExplodedNodeSet& Dst, bool asLValue); > + void VisitCast(CastExpr *CastE, Expr *Ex, ExplodedNode *Pred, > + ExplodedNodeSet &Dst, bool asLValue); > > /// VisitCompoundLiteralExpr - Transfer function logic for compound > literals. > void VisitCompoundLiteralExpr(CompoundLiteralExpr* CL, ExplodedNode* Pred, > > Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=94153&r1=94152&r2=94153&view=diff > > ============================================================================== > --- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original) > +++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Thu Jan 21 22:30:00 2010 > @@ -2173,8 +2173,8 @@ > // Transfer functions: Miscellaneous statements. > //===----------------------------------------------------------------------===// > > -void GRExprEngine::VisitCast(Expr* CastE, Expr* Ex, ExplodedNode* Pred, > - ExplodedNodeSet& Dst, bool asLValue){ > +void GRExprEngine::VisitCast(CastExpr *CastE, Expr *Ex, ExplodedNode *Pred, > + ExplodedNodeSet &Dst, bool asLValue) { > ExplodedNodeSet S1; > QualType T = CastE->getType(); > QualType ExTy = Ex->getType(); > @@ -2191,14 +2191,6 @@ > ExplodedNodeSet S2; > CheckerVisit(CastE, S2, S1, true); > > - // Check for casting to "void". > - if (T->isVoidType()) { > - assert(!asLValue); > - for (ExplodedNodeSet::iterator I = S2.begin(), E = S2.end(); I != E; ++I) > - Dst.Add(*I); > - return; > - } > - > // If we are evaluating the cast in an lvalue context, we implicitly want > // the cast to evaluate to a location. > if (asLValue) { > @@ -2207,13 +2199,51 @@ > ExTy = Ctx.getPointerType(Ctx.getCanonicalType(ExTy)); > } > > - for (ExplodedNodeSet::iterator I = S2.begin(), E = S2.end(); I != E; ++I) { > - ExplodedNode* N = *I; > - const GRState* state = GetState(N); > - SVal V = state->getSVal(Ex); > - const SValuator::CastResult &Res = SVator.EvalCast(V, state, T, ExTy); > - state = Res.getState()->BindExpr(CastE, Res.getSVal()); > - MakeNode(Dst, CastE, N, state); > + switch (CastE->getCastKind()) { > + case CastExpr::CK_ToVoid: > + assert(!asLValue); > + for (ExplodedNodeSet::iterator I = S2.begin(), E = S2.end(); I != E; ++I) > + Dst.Add(*I); > + return; > + > + case CastExpr::CK_NoOp: > + case CastExpr::CK_FunctionToPointerDecay: > + for (ExplodedNodeSet::iterator I = S2.begin(), E = S2.end(); I != E; > ++I) { > + // Copy the SVal of Ex to CastE. > + ExplodedNode *N = *I; > + const GRState *state = GetState(N); > + SVal V = state->getSVal(Ex); > + state = state->BindExpr(CastE, V); > + MakeNode(Dst, CastE, N, state); > + } > + return; > + > + case CastExpr::CK_Unknown: > + case CastExpr::CK_ArrayToPointerDecay: > + case CastExpr::CK_BitCast: > + case CastExpr::CK_IntegralCast: > + case CastExpr::CK_IntegralToPointer: > + case CastExpr::CK_PointerToIntegral: > + case CastExpr::CK_IntegralToFloating: > + case CastExpr::CK_FloatingToIntegral: > + case CastExpr::CK_FloatingCast: > + case CastExpr::CK_AnyPointerToObjCPointerCast: > + case CastExpr::CK_AnyPointerToBlockPointerCast: > + case CastExpr::CK_DerivedToBase: > + // Delegate to SValuator to process. > + for (ExplodedNodeSet::iterator I = S2.begin(), E = S2.end(); I != E; > ++I) { > + ExplodedNode* N = *I; > + const GRState* state = GetState(N); > + SVal V = state->getSVal(Ex); > + const SValuator::CastResult &Res = SVator.EvalCast(V, state, T, ExTy); > + state = Res.getState()->BindExpr(CastE, Res.getSVal()); > + MakeNode(Dst, CastE, N, state); > + } > + return; > + > + default: > + llvm::errs() << "Cast kind " << CastE->getCastKind() << " not > handled.\n"; > + assert(0); > } > } > > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
