From a88b93ed6275d2c37408eb3606fe1370c1cd0f7c Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Wed, 3 Feb 2016 15:20:51 +0000 Subject: [PATCH] Minor cleanup to remove casts and improve some const correctness. NFC. Patch by Alexander Riccio. llvm-svn: 259652 --- .../StaticAnalyzer/Core/PathSensitive/MemRegion.h | 4 +- clang/lib/StaticAnalyzer/Core/MemRegion.cpp | 52 +++++++++++----------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h index 41935aef..1d33301 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h @@ -1320,8 +1320,8 @@ public: void setTrait(SymbolRef Sym, InvalidationKinds IK); void setTrait(const MemRegion *MR, InvalidationKinds IK); - bool hasTrait(SymbolRef Sym, InvalidationKinds IK); - bool hasTrait(const MemRegion *MR, InvalidationKinds IK); + bool hasTrait(SymbolRef Sym, InvalidationKinds IK) const; + bool hasTrait(const MemRegion *MR, InvalidationKinds IK) const; }; } // end GR namespace diff --git a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp index 84c1198..11dfb9d 100644 --- a/clang/lib/StaticAnalyzer/Core/MemRegion.cpp +++ b/clang/lib/StaticAnalyzer/Core/MemRegion.cpp @@ -46,7 +46,7 @@ RegionTy* MemRegionManager::getRegion(const A1 a1) { InsertPos)); if (!R) { - R = (RegionTy*) A.Allocate(); + R = A.Allocate(); new (R) RegionTy(a1, superRegion); Regions.InsertNode(R, InsertPos); } @@ -64,7 +64,7 @@ RegionTy* MemRegionManager::getSubRegion(const A1 a1, InsertPos)); if (!R) { - R = (RegionTy*) A.Allocate(); + R = A.Allocate(); new (R) RegionTy(a1, superRegion); Regions.InsertNode(R, InsertPos); } @@ -85,7 +85,7 @@ RegionTy* MemRegionManager::getRegion(const A1 a1, const A2 a2) { InsertPos)); if (!R) { - R = (RegionTy*) A.Allocate(); + R = A.Allocate(); new (R) RegionTy(a1, a2, superRegion); Regions.InsertNode(R, InsertPos); } @@ -104,7 +104,7 @@ RegionTy* MemRegionManager::getSubRegion(const A1 a1, const A2 a2, InsertPos)); if (!R) { - R = (RegionTy*) A.Allocate(); + R = A.Allocate(); new (R) RegionTy(a1, a2, superRegion); Regions.InsertNode(R, InsertPos); } @@ -123,7 +123,7 @@ RegionTy* MemRegionManager::getSubRegion(const A1 a1, const A2 a2, const A3 a3, InsertPos)); if (!R) { - R = (RegionTy*) A.Allocate(); + R = A.Allocate(); new (R) RegionTy(a1, a2, a3, superRegion); Regions.InsertNode(R, InsertPos); } @@ -246,23 +246,23 @@ QualType CXXBaseObjectRegion::getValueType() const { //===----------------------------------------------------------------------===// void MemSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const { - ID.AddInteger((unsigned)getKind()); + ID.AddInteger(static_cast(getKind())); } void StackSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const { - ID.AddInteger((unsigned)getKind()); + ID.AddInteger(static_cast(getKind())); ID.AddPointer(getStackFrame()); } void StaticGlobalSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const { - ID.AddInteger((unsigned)getKind()); + ID.AddInteger(static_cast(getKind())); ID.AddPointer(getCodeRegion()); } void StringRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, const StringLiteral* Str, const MemRegion* superRegion) { - ID.AddInteger((unsigned) StringRegionKind); + ID.AddInteger(static_cast(StringRegionKind)); ID.AddPointer(Str); ID.AddPointer(superRegion); } @@ -270,7 +270,7 @@ void StringRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, void ObjCStringRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, const ObjCStringLiteral* Str, const MemRegion* superRegion) { - ID.AddInteger((unsigned) ObjCStringRegionKind); + ID.AddInteger(static_cast(ObjCStringRegionKind)); ID.AddPointer(Str); ID.AddPointer(superRegion); } @@ -278,7 +278,7 @@ void ObjCStringRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, const Expr *Ex, unsigned cnt, const MemRegion *superRegion) { - ID.AddInteger((unsigned) AllocaRegionKind); + ID.AddInteger(static_cast(AllocaRegionKind)); ID.AddPointer(Ex); ID.AddInteger(cnt); ID.AddPointer(superRegion); @@ -295,7 +295,7 @@ void CompoundLiteralRegion::Profile(llvm::FoldingSetNodeID& ID) const { void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, const CompoundLiteralExpr *CL, const MemRegion* superRegion) { - ID.AddInteger((unsigned) CompoundLiteralRegionKind); + ID.AddInteger(static_cast(CompoundLiteralRegionKind)); ID.AddPointer(CL); ID.AddPointer(superRegion); } @@ -303,7 +303,7 @@ void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, void CXXThisRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, const PointerType *PT, const MemRegion *sRegion) { - ID.AddInteger((unsigned) CXXThisRegionKind); + ID.AddInteger(static_cast(CXXThisRegionKind)); ID.AddPointer(PT); ID.AddPointer(sRegion); } @@ -320,7 +320,7 @@ void ObjCIvarRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, void DeclRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, const Decl *D, const MemRegion* superRegion, Kind k) { - ID.AddInteger((unsigned) k); + ID.AddInteger(static_cast(k)); ID.AddPointer(D); ID.AddPointer(superRegion); } @@ -335,7 +335,7 @@ void VarRegion::Profile(llvm::FoldingSetNodeID &ID) const { void SymbolicRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, SymbolRef sym, const MemRegion *sreg) { - ID.AddInteger((unsigned) MemRegion::SymbolicRegionKind); + ID.AddInteger(static_cast(MemRegion::SymbolicRegionKind)); ID.Add(sym); ID.AddPointer(sreg); } @@ -454,7 +454,7 @@ void MemRegion::dumpToStream(raw_ostream &os) const { } void AllocaRegion::dumpToStream(raw_ostream &os) const { - os << "alloca{" << (const void*) Ex << ',' << Cnt << '}'; + os << "alloca{" << static_cast(Ex) << ',' << Cnt << '}'; } void FunctionCodeRegion::dumpToStream(raw_ostream &os) const { @@ -462,7 +462,7 @@ void FunctionCodeRegion::dumpToStream(raw_ostream &os) const { } void BlockCodeRegion::dumpToStream(raw_ostream &os) const { - os << "block_code{" << (const void*) this << '}'; + os << "block_code{" << static_cast(this) << '}'; } void BlockDataRegion::dumpToStream(raw_ostream &os) const { @@ -478,12 +478,12 @@ void BlockDataRegion::dumpToStream(raw_ostream &os) const { void CompoundLiteralRegion::dumpToStream(raw_ostream &os) const { // FIXME: More elaborate pretty-printing. - os << "{ " << (const void*) CL << " }"; + os << "{ " << static_cast(CL) << " }"; } void CXXTempObjectRegion::dumpToStream(raw_ostream &os) const { os << "temp_object{" << getValueType().getAsString() << ',' - << (const void*) Ex << '}'; + << static_cast(Ex) << '}'; } void CXXBaseObjectRegion::dumpToStream(raw_ostream &os) const { @@ -646,7 +646,7 @@ void CXXBaseObjectRegion::printPrettyAsExpr(raw_ostream &os) const { template const REG *MemRegionManager::LazyAllocate(REG*& region) { if (!region) { - region = (REG*) A.Allocate(); + region = A.Allocate(); new (region) REG(this); } @@ -656,7 +656,7 @@ const REG *MemRegionManager::LazyAllocate(REG*& region) { template const REG *MemRegionManager::LazyAllocate(REG*& region, ARG a) { if (!region) { - region = (REG*) A.Allocate(); + region = A.Allocate(); new (region) REG(this, a); } @@ -921,7 +921,7 @@ MemRegionManager::getElementRegion(QualType elementType, NonLoc Idx, ElementRegion* R = cast_or_null(data); if (!R) { - R = (ElementRegion*) A.Allocate(); + R = A.Allocate(); new (R) ElementRegion(T, Idx, superRegion); Regions.InsertNode(R, InsertPos); } @@ -1342,10 +1342,10 @@ RegionOffset MemRegion::getAsOffset() const { // Get the field number. unsigned idx = 0; for (RecordDecl::field_iterator FI = RD->field_begin(), - FE = RD->field_end(); FI != FE; ++FI, ++idx) + FE = RD->field_end(); FI != FE; ++FI, ++idx) { if (FR->getDecl() == *FI) break; - + } const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD); // This is offset in bits. Offset += Layout.getFieldOffset(idx); @@ -1488,7 +1488,7 @@ void RegionAndSymbolInvalidationTraits::setTrait(const MemRegion *MR, } bool RegionAndSymbolInvalidationTraits::hasTrait(SymbolRef Sym, - InvalidationKinds IK) { + InvalidationKinds IK) const { const_symbol_iterator I = SymTraitsMap.find(Sym); if (I != SymTraitsMap.end()) return I->second & IK; @@ -1497,7 +1497,7 @@ bool RegionAndSymbolInvalidationTraits::hasTrait(SymbolRef Sym, } bool RegionAndSymbolInvalidationTraits::hasTrait(const MemRegion *MR, - InvalidationKinds IK) { + InvalidationKinds IK) const { if (!MR) return false; -- 2.7.4