[cfe-commits] r58137 - in /cfe/trunk: include/clang/Analysis/PathSensitive/MemRegion.h lib/Analysis/MemRegion.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Sat Oct 25 07:13:41 PDT 2008
Author: zhongxingxu
Date: Sat Oct 25 09:13:41 2008
New Revision: 58137
URL: http://llvm.org/viewvc/llvm-project?rev=58137&view=rev
Log:
Add StringRegion to MemRegions.
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=58137&r1=58136&r2=58137&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Sat Oct 25 09:13:41 2008
@@ -38,8 +38,11 @@
enum Kind { MemSpaceRegionKind, SymbolicRegionKind,
// Typed regions.
BEG_TYPED_REGIONS,
- VarRegionKind, FieldRegionKind, ElementRegionKind,
+ StringRegionKind, ElementRegionKind,
+ BEG_DECL_REGIONS,
+ VarRegionKind, FieldRegionKind,
ObjCIvarRegionKind, ObjCObjectRegionKind,
+ END_DECL_REGIONS,
AnonTypedRegionKind, AnonPointeeRegionKind,
END_TYPED_REGIONS };
private:
@@ -135,6 +138,35 @@
}
};
+/// StringRegion - Region associated with a StringLiteral.
+class StringRegion : public TypedRegion {
+ friend class MemRegionManager;
+
+ const StringLiteral* Str;
+
+protected:
+
+ StringRegion(const StringLiteral* str, MemRegion* sreg)
+ : TypedRegion(sreg, StringRegionKind), Str(str) {}
+
+ static void ProfileRegion(llvm::FoldingSetNodeID& ID,
+ const StringLiteral* Str,
+ const MemRegion* superRegion);
+
+public:
+ QualType getType(ASTContext&) const {
+ return Str->getType();
+ }
+
+ void Profile(llvm::FoldingSetNodeID& ID) const {
+ ProfileRegion(ID, Str, superRegion);
+ }
+
+ static bool classof(const MemRegion* R) {
+ return R->getKind() == StringRegionKind;
+ }
+};
+
/// AnonTypedRegion - An "anonymous" region that simply types a chunk
/// of memory.
class AnonTypedRegion : public TypedRegion {
@@ -195,6 +227,11 @@
public:
const Decl* getDecl() const { return D; }
void Profile(llvm::FoldingSetNodeID& ID) const;
+
+ static bool classof(const MemRegion* R) {
+ unsigned k = R->getKind();
+ return k > BEG_DECL_REGIONS && k < END_DECL_REGIONS;
+ }
};
class VarRegion : public DeclRegion {
@@ -351,7 +388,9 @@
/// getSymbolicRegion - Retrieve or create a "symbolic" memory region.
SymbolicRegion* getSymbolicRegion(const SymbolID sym);
-
+
+ StringRegion* getStringRegion(const StringLiteral* Str);
+
/// getVarRegion - Retrieve or create the memory region associated with
/// a specified VarDecl. 'superRegion' corresponds to the containing
/// memory region, and 'off' is the offset within the containing region.
Modified: cfe/trunk/lib/Analysis/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=58137&r1=58136&r2=58137&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Sat Oct 25 09:13:41 2008
@@ -25,6 +25,14 @@
ID.AddInteger((unsigned)getKind());
}
+void StringRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
+ const StringLiteral* Str,
+ const MemRegion* superRegion) {
+ ID.AddInteger((unsigned) StringRegionKind);
+ ID.AddPointer(Str);
+ ID.AddPointer(superRegion);
+}
+
void AnonTypedRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, QualType T,
const MemRegion* superRegion) {
ID.AddInteger((unsigned) AnonTypedRegionKind);
@@ -138,6 +146,25 @@
return LazyAllocate(unknown);
}
+StringRegion* MemRegionManager::getStringRegion(const StringLiteral* Str) {
+ llvm::FoldingSetNodeID ID;
+ MemSpaceRegion* GlobalsR = getGlobalsRegion();
+
+ StringRegion::ProfileRegion(ID, Str, GlobalsR);
+
+ void* InsertPos;
+ MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
+ StringRegion* R = cast_or_null<StringRegion>(data);
+
+ if (!R) {
+ R = (StringRegion*) A.Allocate<StringRegion>();
+ new (R) StringRegion(Str, GlobalsR);
+ Regions.InsertNode(R, InsertPos);
+ }
+
+ return R;
+}
+
VarRegion* MemRegionManager::getVarRegion(const VarDecl* d,
const MemRegion* superRegion) {
llvm::FoldingSetNodeID ID;
More information about the cfe-commits
mailing list