diff options
| author | Jordan Rose <jordan_rose@apple.com> | 2013-05-02 19:51:20 +0000 | 
|---|---|---|
| committer | Jordan Rose <jordan_rose@apple.com> | 2013-05-02 19:51:20 +0000 | 
| commit | c76d7e3d96dc053865a7f334c41727346d67ec78 (patch) | |
| tree | 0a268e7a99d14773b2d8efe336cbf362d4acd662 /clang/lib/StaticAnalyzer/Core | |
| parent | f3805157536d143210ec1822baa5733bb2c5beff (diff) | |
| download | bcm5719-llvm-c76d7e3d96dc053865a7f334c41727346d67ec78.tar.gz bcm5719-llvm-c76d7e3d96dc053865a7f334c41727346d67ec78.zip | |
[analyzer] Don't try to evaluate MaterializeTemporaryExpr as a constant.
...and don't consider '0' to be a null pointer constant if it's the
initializer for a float!
Apparently null pointer constant evaluation looks through both
MaterializeTemporaryExpr and ImplicitCastExpr, so we have to be more
careful about types in the callers. For RegionStore this just means giving
up a little more; for ExprEngine this means handling the
MaterializeTemporaryExpr case explicitly.
Follow-up to r180894.
llvm-svn: 180944
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core')
| -rw-r--r-- | clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 9 | ||||
| -rw-r--r-- | clang/lib/StaticAnalyzer/Core/SValBuilder.cpp | 9 | 
2 files changed, 15 insertions, 3 deletions
| diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 0d5fb1785b3..bfe4e15a715 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -741,6 +741,13 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,        const CXXDefaultArgExpr *DefaultE = cast<CXXDefaultArgExpr>(S);        const Expr *ArgE = DefaultE->getExpr(); +      bool IsTemporary = false; +      if (const MaterializeTemporaryExpr *MTE = +            dyn_cast<MaterializeTemporaryExpr>(ArgE)) { +        ArgE = MTE->GetTemporaryExpr(); +        IsTemporary = true; +      } +        Optional<SVal> ConstantVal = svalBuilder.getConstantVal(ArgE);        if (!ConstantVal)          ConstantVal = UnknownVal(); @@ -749,7 +756,7 @@ void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,             I != E; ++I) {          ProgramStateRef State = (*I)->getState();          State = State->BindExpr(DefaultE, LCtx, *ConstantVal); -        if (DefaultE->isGLValue()) +        if (IsTemporary)            State = createTemporaryRegionIfNeeded(State, LCtx, DefaultE,                                                  DefaultE);          Bldr2.generateNode(S, *I, State); diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp index 652809777cf..9d77a3ef58f 100644 --- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -268,13 +268,18 @@ Optional<SVal> SValBuilder::getConstantVal(const Expr *E) {    // If we don't have a special case, fall back to the AST's constant evaluator.    default: { +    // Don't try to come up with a value for materialized temporaries. +    if (E->isGLValue()) +      return None; +      ASTContext &Ctx = getContext();      llvm::APSInt Result;      if (E->EvaluateAsInt(Result, Ctx))        return makeIntVal(Result); -    if (E->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull)) -      return makeNull(); +    if (Loc::isLocType(E->getType())) +      if (E->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull)) +        return makeNull();      return None;    } | 

