aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/MemRegion.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-10-27 20:57:58 +0000
committerTed Kremenek <kremenek@apple.com>2008-10-27 20:57:58 +0000
commit329d6fde79254503b14724e1231a9d70fa6b387f (patch)
tree3a79c6cf173dea3eb5d3457cf01b2c6d29ff5588 /lib/Analysis/MemRegion.cpp
parent80c28553e08d5f294801bc51f0e91df43f64a940 (diff)
Added CompoundLiteralRegion to represent the (temporary) memory allocated for a compound literal.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58270 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/MemRegion.cpp')
-rw-r--r--lib/Analysis/MemRegion.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp
index 1db330cf09..8a7be0d564 100644
--- a/lib/Analysis/MemRegion.cpp
+++ b/lib/Analysis/MemRegion.cpp
@@ -53,6 +53,18 @@ void AnonTypedRegion::Profile(llvm::FoldingSetNodeID& ID) const {
AnonTypedRegion::ProfileRegion(ID, T, superRegion);
}
+void CompoundLiteralRegion::Profile(llvm::FoldingSetNodeID& ID) const {
+ CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion);
+}
+
+void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
+ const CompoundLiteralExpr* CL,
+ const MemRegion* superRegion) {
+ ID.AddInteger((unsigned) CompoundLiteralRegionKind);
+ ID.AddPointer(CL);
+ ID.AddPointer(superRegion);
+}
+
void DeclRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, const Decl* D,
const MemRegion* superRegion, Kind k) {
ID.AddInteger((unsigned) k);
@@ -123,6 +135,11 @@ void ElementRegion::print(llvm::raw_ostream& os) const {
os << '['; Index.print(os); os << ']';
}
+void CompoundLiteralRegion::print(llvm::raw_ostream& os) const {
+ // FIXME: More elaborate pretty-printing.
+ os << "{ " << (void*) CL << " }";
+}
+
//===----------------------------------------------------------------------===//
// MemRegionManager methods.
//===----------------------------------------------------------------------===//
@@ -190,6 +207,30 @@ VarRegion* MemRegionManager::getVarRegion(const VarDecl* d,
return R;
}
+CompoundLiteralRegion*
+MemRegionManager::getCompoundLiteralRegion(const CompoundLiteralExpr* CL) {
+ // Is this compound literal allocated on the stack or is part of the
+ // global constant pool?
+ const MemRegion* superRegion = CL->isFileScope() ?
+ getGlobalsRegion() : getStackRegion();
+
+ // Profile the compound literal.
+ llvm::FoldingSetNodeID ID;
+ CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion);
+
+ void* InsertPos;
+ MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
+ CompoundLiteralRegion* R = cast_or_null<CompoundLiteralRegion>(data);
+
+ if (!R) {
+ R = (CompoundLiteralRegion*) A.Allocate<CompoundLiteralRegion>();
+ new (R) CompoundLiteralRegion(CL, superRegion);
+ Regions.InsertNode(R, InsertPos);
+ }
+
+ return R;
+}
+
ElementRegion* MemRegionManager::getElementRegion(SVal Idx,
const MemRegion* superRegion){
llvm::FoldingSetNodeID ID;