diff options
author | Eugene Zelenko <eugene.zelenko@gmail.com> | 2018-03-06 00:47:41 +0000 |
---|---|---|
committer | Eugene Zelenko <eugene.zelenko@gmail.com> | 2018-03-06 00:47:41 +0000 |
commit | b8b9af2ad46ff1ed901956c155c48c15cb585fa9 (patch) | |
tree | e30df267319a779c81a74da74de6f3d7f6722df8 /clang/lib/StaticAnalyzer/Core/SValBuilder.cpp | |
parent | a1bd9508e02c9c59dff0962e15abbbd1e0e677b7 (diff) | |
download | bcm5719-llvm-b8b9af2ad46ff1ed901956c155c48c15cb585fa9.tar.gz bcm5719-llvm-b8b9af2ad46ff1ed901956c155c48c15cb585fa9.zip |
[StaticAnalyzer] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 326757
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/SValBuilder.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/SValBuilder.cpp | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp index f49995d50cc..ab5ec9f12fc 100644 --- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -1,4 +1,4 @@ -// SValBuilder.cpp - Basic class for all SValBuilder implementations -*- C++ -*- +//===- SValBuilder.cpp - Basic class for all SValBuilder implementations --===// // // The LLVM Compiler Infrastructure // @@ -13,12 +13,31 @@ //===----------------------------------------------------------------------===// #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/ExprCXX.h" +#include "clang/AST/ExprObjC.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/Type.h" +#include "clang/Basic/LLVM.h" +#include "clang/Analysis/AnalysisDeclContext.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h" #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h" #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h" #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/Store.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/ADT/None.h" +#include "llvm/ADT/Optional.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" +#include <cassert> +#include <tuple> using namespace clang; using namespace ento; @@ -27,7 +46,7 @@ using namespace ento; // Basic SVal creation. //===----------------------------------------------------------------------===// -void SValBuilder::anchor() { } +void SValBuilder::anchor() {} DefinedOrUnknownSVal SValBuilder::makeZeroVal(QualType type) { if (Loc::isLocType(type)) @@ -95,7 +114,7 @@ nonloc::ConcreteInt SValBuilder::makeBoolVal(const CXXBoolLiteralExpr *boolean){ } DefinedOrUnknownSVal -SValBuilder::getRegionValueSymbolVal(const TypedValueRegion* region) { +SValBuilder::getRegionValueSymbolVal(const TypedValueRegion *region) { QualType T = region->getValueType(); if (T->isNullPtrType()) @@ -149,7 +168,6 @@ DefinedOrUnknownSVal SValBuilder::conjureSymbolVal(const void *symbolTag, return nonloc::SymbolVal(sym); } - DefinedOrUnknownSVal SValBuilder::conjureSymbolVal(const Stmt *stmt, const LocationContext *LCtx, QualType type, @@ -217,10 +235,10 @@ SValBuilder::getDerivedRegionValueSymbolVal(SymbolRef parentSymbol, return nonloc::SymbolVal(sym); } -DefinedSVal SValBuilder::getMemberPointer(const DeclaratorDecl* DD) { +DefinedSVal SValBuilder::getMemberPointer(const DeclaratorDecl *DD) { assert(!DD || isa<CXXMethodDecl>(DD) || isa<FieldDecl>(DD)); - if (auto *MD = dyn_cast_or_null<CXXMethodDecl>(DD)) { + if (const auto *MD = dyn_cast_or_null<CXXMethodDecl>(DD)) { // Sema treats pointers to static member functions as have function pointer // type, so return a function pointer for the method. // We don't need to play a similar trick for static member fields @@ -277,19 +295,19 @@ Optional<SVal> SValBuilder::getConstantVal(const Expr *E) { return makeZeroVal(E->getType()); case Stmt::ObjCStringLiteralClass: { - const ObjCStringLiteral *SL = cast<ObjCStringLiteral>(E); + const auto *SL = cast<ObjCStringLiteral>(E); return makeLoc(getRegionManager().getObjCStringRegion(SL)); } case Stmt::StringLiteralClass: { - const StringLiteral *SL = cast<StringLiteral>(E); + const auto *SL = cast<StringLiteral>(E); return makeLoc(getRegionManager().getStringRegion(SL)); } // Fast-path some expressions to avoid the overhead of going through the AST's // constant evaluator case Stmt::CharacterLiteralClass: { - const CharacterLiteral *C = cast<CharacterLiteral>(E); + const auto *C = cast<CharacterLiteral>(E); return makeIntVal(C->getValue(), C->getType()); } @@ -297,7 +315,7 @@ Optional<SVal> SValBuilder::getConstantVal(const Expr *E) { return makeBoolVal(cast<CXXBoolLiteralExpr>(E)); case Stmt::TypeTraitExprClass: { - const TypeTraitExpr *TE = cast<TypeTraitExpr>(E); + const auto *TE = cast<TypeTraitExpr>(E); return makeTruthVal(TE->getValue(), TE->getType()); } @@ -311,7 +329,7 @@ Optional<SVal> SValBuilder::getConstantVal(const Expr *E) { return makeNull(); case Stmt::ImplicitCastExprClass: { - const CastExpr *CE = cast<CastExpr>(E); + const auto *CE = cast<CastExpr>(E); switch (CE->getCastKind()) { default: break; @@ -348,8 +366,6 @@ Optional<SVal> SValBuilder::getConstantVal(const Expr *E) { } } -//===----------------------------------------------------------------------===// - SVal SValBuilder::makeSymExprValNN(ProgramStateRef State, BinaryOperator::Opcode Op, NonLoc LHS, NonLoc RHS, @@ -378,10 +394,8 @@ SVal SValBuilder::makeSymExprValNN(ProgramStateRef State, return UnknownVal(); } - SVal SValBuilder::evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op, SVal lhs, SVal rhs, QualType type) { - if (lhs.isUndef() || rhs.isUndef()) return UndefinedVal(); @@ -463,7 +477,6 @@ static bool shouldBeModeledWithNoOp(ASTContext &Context, QualType ToTy, // of the original value is known to be greater than the max of the target type. SVal SValBuilder::evalIntegralCast(ProgramStateRef state, SVal val, QualType castTy, QualType originalTy) { - // No truncations if target type is big enough. if (getContext().getTypeSize(castTy) >= getContext().getTypeSize(originalTy)) return evalCast(val, castTy, originalTy); @@ -557,8 +570,8 @@ SVal SValBuilder::evalCast(SVal val, QualType castTy, QualType originalTy) { } // Check for casts from array type to another type. - if (const ArrayType *arrayT = - dyn_cast<ArrayType>(originalTy.getCanonicalType())) { + if (const auto *arrayT = + dyn_cast<ArrayType>(originalTy.getCanonicalType())) { // We will always decay to a pointer. QualType elemTy = arrayT->getElementType(); val = StateMgr.ArrayToPointer(val.castAs<Loc>(), elemTy); |