[cfe-commits] r58595 - in /cfe/trunk: include/clang/Analysis/PathSensitive/MemRegion.h lib/Analysis/MemRegion.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Sun Nov 2 20:12:30 PST 2008
Author: zhongxingxu
Date: Sun Nov 2 22:12:24 2008
New Revision: 58595
URL: http://llvm.org/viewvc/llvm-project?rev=58595&view=rev
Log:
- Remove AnonTypedRegion, which is not to be used.
- Prepare AnonPointeeRegioin for later use.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
cfe/trunk/lib/Analysis/MemRegion.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h?rev=58595&r1=58594&r2=58595&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Sun Nov 2 22:12:24 2008
@@ -47,7 +47,7 @@
VarRegionKind, FieldRegionKind,
ObjCIvarRegionKind, ObjCObjectRegionKind,
END_DECL_REGIONS,
- AnonTypedRegionKind, AnonPointeeRegionKind,
+ AnonPointeeRegionKind,
END_TYPED_REGIONS };
private:
const Kind kind;
@@ -199,53 +199,35 @@
}
};
-/// AnonTypedRegion - An "anonymous" region that simply types a chunk
-/// of memory.
-class AnonTypedRegion : public TypedRegion {
-protected:
- QualType T;
+/// AnonPointeeRegion - anonymous regions pointed-to by pointer function
+/// parameters or pointer globals. In RegionStoreManager, we assume pointer
+/// parameters or globals point at some anonymous region. Such regions are not
+/// the regions associated with the pointer variables themselves. They are
+/// identified with the VarDecl of the pointer variable. We create them lazily.
+class AnonPointeeRegion : public TypedRegion {
friend class MemRegionManager;
-
- AnonTypedRegion(QualType t, MemRegion* sreg)
- : TypedRegion(sreg, AnonTypedRegionKind), T(t) {}
+ // VD - the pointer variable that points at this region.
+ const VarDecl* Pointer;
- static void ProfileRegion(llvm::FoldingSetNodeID& ID, QualType T,
- const MemRegion* superRegion);
+ AnonPointeeRegion(const VarDecl* d, MemRegion* sreg)
+ : TypedRegion(sreg, AnonPointeeRegionKind), Pointer(d) {}
public:
- QualType getType(ASTContext& C) const { return C.getCanonicalType(T); }
-
+ QualType getType(ASTContext& C) const;
- void Profile(llvm::FoldingSetNodeID& ID) const;
-
- static bool classof(const MemRegion* R) {
- return R->getKind() == AnonTypedRegionKind;
- }
-};
-
-/// AnonPointeeRegion - anonymous regions pointed-at by pointer function
-/// parameters or pointer globals. In RegionStoreManager, we assume pointer
-/// parameters or globals point at some anonymous region initially. Such
-/// regions are not the regions associated with the pointers themselves, but
-/// are identified with the VarDecl of the parameters or globals.
-class AnonPointeeRegion : public AnonTypedRegion {
- friend class MemRegionManager;
- // VD - the pointer variable that points at this region.
- const VarDecl* VD;
+ static void ProfileRegion(llvm::FoldingSetNodeID& ID, const VarDecl* PVD,
+ const MemRegion* superRegion);
- AnonPointeeRegion(const VarDecl* d, QualType t, MemRegion* sreg)
- : AnonTypedRegion(t, sreg), VD(d) {}
+ void Profile(llvm::FoldingSetNodeID& ID) const {
+ ProfileRegion(ID, Pointer, superRegion);
+ }
-public:
- static void ProfileRegion(llvm::FoldingSetNodeID& ID, const VarDecl* PVD,
- QualType T, const MemRegion* superRegion);
+ static bool classof(const MemRegion* R) {
+ return R->getKind() == AnonPointeeRegionKind;
+ }
};
-/// AnonHeapRegion - anonymous region created by malloc().
-class AnonHeapRegion : public AnonTypedRegion {
-};
-
/// CompoundLiteralRegion - A memory region representing a compound literal.
/// Compound literals are essentially temporaries that are stack allocated
/// or in the global constant pool.
Modified: cfe/trunk/lib/Analysis/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=58595&r1=58594&r2=58595&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Sun Nov 2 22:12:24 2008
@@ -44,26 +44,22 @@
ProfileRegion(ID, Ex, Cnt);
}
-void AnonTypedRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, QualType T,
- const MemRegion* superRegion) {
- ID.AddInteger((unsigned) AnonTypedRegionKind);
- ID.Add(T);
- ID.AddPointer(superRegion);
+QualType AnonPointeeRegion::getType(ASTContext& C) const {
+ QualType T = C.getCanonicalType(Pointer->getType());
+ PointerType* PTy = cast<PointerType>(T.getTypePtr());
+
+ QualType PointeeTy = C.getCanonicalType(PTy->getPointeeType());
+ return PointeeTy;
}
void AnonPointeeRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
- const VarDecl* VD, QualType T,
+ const VarDecl* VD,
const MemRegion* superRegion) {
ID.AddInteger((unsigned) AnonPointeeRegionKind);
- ID.Add(T);
ID.AddPointer(VD);
ID.AddPointer(superRegion);
}
-void AnonTypedRegion::Profile(llvm::FoldingSetNodeID& ID) const {
- AnonTypedRegion::ProfileRegion(ID, T, superRegion);
-}
-
void CompoundLiteralRegion::Profile(llvm::FoldingSetNodeID& ID) const {
CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion);
}
@@ -346,11 +342,9 @@
AnonPointeeRegion* MemRegionManager::getAnonPointeeRegion(const VarDecl* d) {
llvm::FoldingSetNodeID ID;
- QualType T = d->getType();
- QualType PointeeType = cast<PointerType>(T.getTypePtr())->getPointeeType();
MemRegion* superRegion = getUnknownRegion();
- AnonPointeeRegion::ProfileRegion(ID, d, PointeeType, superRegion);
+ AnonPointeeRegion::ProfileRegion(ID, d, superRegion);
void* InsertPos;
MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
@@ -358,7 +352,7 @@
if (!R) {
R = (AnonPointeeRegion*) A.Allocate<AnonPointeeRegion>();
- new (R) AnonPointeeRegion(d, PointeeType, superRegion);
+ new (R) AnonPointeeRegion(d, superRegion);
Regions.InsertNode(R, InsertPos);
}
More information about the cfe-commits
mailing list