aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Checker/PathSensitive/MemRegion.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/Checker/PathSensitive/MemRegion.h')
-rw-r--r--include/clang/Checker/PathSensitive/MemRegion.h127
1 files changed, 72 insertions, 55 deletions
diff --git a/include/clang/Checker/PathSensitive/MemRegion.h b/include/clang/Checker/PathSensitive/MemRegion.h
index feb4b7218a7e..96f906af28e1 100644
--- a/include/clang/Checker/PathSensitive/MemRegion.h
+++ b/include/clang/Checker/PathSensitive/MemRegion.h
@@ -20,6 +20,7 @@
#include "clang/AST/DeclObjC.h"
#include "clang/Checker/PathSensitive/SVals.h"
#include "llvm/Support/Casting.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/ADT/FoldingSet.h"
#include <string>
@@ -38,6 +39,22 @@ class ValueManager;
class VarRegion;
class CodeTextRegion;
+/// Represent a region's offset within the top level base region.
+class RegionOffset {
+ /// The base region.
+ const MemRegion *R;
+
+ /// The bit offset within the base region. It shouldn't be negative.
+ int64_t Offset;
+
+public:
+ RegionOffset(const MemRegion *r) : R(r), Offset(0) {}
+ RegionOffset(const MemRegion *r, int64_t off) : R(r), Offset(off) {}
+
+ const MemRegion *getRegion() const { return R; }
+ int64_t getOffset() const { return Offset; }
+};
+
//===----------------------------------------------------------------------===//
// Base region classes.
//===----------------------------------------------------------------------===//
@@ -111,6 +128,9 @@ public:
bool hasStackParametersStorage() const;
+ /// Compute the offset within the top level memory object.
+ RegionOffset getAsOffset() const;
+
virtual void dumpToStream(llvm::raw_ostream& os) const;
void dump() const;
@@ -261,6 +281,7 @@ public:
}
};
+
/// SubRegion - A region that subsets another larger region. Most regions
/// are subclasses of SubRegion.
class SubRegion : public MemRegion {
@@ -287,31 +308,6 @@ public:
};
//===----------------------------------------------------------------------===//
-// Auxillary data classes for use with MemRegions.
-//===----------------------------------------------------------------------===//
-
-class ElementRegion;
-
-class RegionRawOffset {
-private:
- friend class ElementRegion;
-
- const MemRegion *Region;
- int64_t Offset;
-
- RegionRawOffset(const MemRegion* reg, int64_t offset = 0)
- : Region(reg), Offset(offset) {}
-
-public:
- // FIXME: Eventually support symbolic offsets.
- int64_t getByteOffset() const { return Offset; }
- const MemRegion *getRegion() const { return Region; }
-
- void dumpToStream(llvm::raw_ostream& os) const;
- void dump() const;
-};
-
-//===----------------------------------------------------------------------===//
// MemRegion subclasses.
//===----------------------------------------------------------------------===//
@@ -353,25 +349,23 @@ protected:
TypedRegion(const MemRegion* sReg, Kind k) : SubRegion(sReg, k) {}
public:
- virtual QualType getValueType(ASTContext &C) const = 0;
+ virtual QualType getValueType() const = 0;
- virtual QualType getLocationType(ASTContext& C) const {
+ virtual QualType getLocationType() const {
// FIXME: We can possibly optimize this later to cache this value.
- return C.getPointerType(getValueType(C));
+ return getContext().getPointerType(getValueType());
}
- QualType getDesugaredValueType(ASTContext& C) const {
- QualType T = getValueType(C);
+ QualType getDesugaredValueType() const {
+ QualType T = getValueType();
return T.getTypePtr() ? T.getDesugaredType() : T;
}
- QualType getDesugaredLocationType(ASTContext& C) const {
- return getLocationType(C).getDesugaredType();
+ QualType getDesugaredLocationType() const {
+ return getLocationType().getDesugaredType();
}
- bool isBoundable() const {
- return !getValueType(getContext()).isNull();
- }
+ bool isBoundable() const { return true; }
static bool classof(const MemRegion* R) {
unsigned k = R->getKind();
@@ -384,9 +378,8 @@ class CodeTextRegion : public TypedRegion {
protected:
CodeTextRegion(const MemRegion *sreg, Kind k) : TypedRegion(sreg, k) {}
public:
- QualType getValueType(ASTContext &C) const {
- // Do not get the object type of a CodeTextRegion.
- assert(0);
+ QualType getValueType() const {
+ assert(0 && "Do not get the object type of a CodeTextRegion.");
return QualType();
}
@@ -405,8 +398,8 @@ public:
FunctionTextRegion(const FunctionDecl* fd, const MemRegion* sreg)
: CodeTextRegion(sreg, FunctionTextRegionKind), FD(fd) {}
- QualType getLocationType(ASTContext &C) const {
- return C.getPointerType(FD->getType());
+ QualType getLocationType() const {
+ return getContext().getPointerType(FD->getType());
}
const FunctionDecl *getDecl() const {
@@ -444,7 +437,7 @@ class BlockTextRegion : public CodeTextRegion {
: CodeTextRegion(sreg, BlockTextRegionKind), BD(bd), AC(ac), locTy(lTy) {}
public:
- QualType getLocationType(ASTContext &C) const {
+ QualType getLocationType() const {
return locTy;
}
@@ -581,7 +574,7 @@ public:
const StringLiteral* getStringLiteral() const { return Str; }
- QualType getValueType(ASTContext& C) const {
+ QualType getValueType() const {
return Str->getType();
}
@@ -615,8 +608,8 @@ private:
const CompoundLiteralExpr* CL,
const MemRegion* superRegion);
public:
- QualType getValueType(ASTContext& C) const {
- return C.getCanonicalType(CL->getType());
+ QualType getValueType() const {
+ return CL->getType();
}
bool isBoundable() const { return !CL->isFileScope(); }
@@ -673,9 +666,9 @@ public:
const StackFrameContext *getStackFrame() const;
- QualType getValueType(ASTContext& C) const {
+ QualType getValueType() const {
// FIXME: We can cache this if needed.
- return C.getCanonicalType(getDecl()->getType());
+ return getDecl()->getType();
}
void dumpToStream(llvm::raw_ostream& os) const;
@@ -701,10 +694,10 @@ class CXXThisRegion : public TypedRegion {
void Profile(llvm::FoldingSetNodeID &ID) const;
public:
- QualType getValueType(ASTContext &C) const {
+ QualType getValueType() const {
return QualType(ThisPointerTy, 0);
}
-
+
void dumpToStream(llvm::raw_ostream& os) const;
static bool classof(const MemRegion* R) {
@@ -727,9 +720,9 @@ public:
const FieldDecl* getDecl() const { return cast<FieldDecl>(D); }
- QualType getValueType(ASTContext& C) const {
+ QualType getValueType() const {
// FIXME: We can cache this if needed.
- return C.getCanonicalType(getDecl()->getType());
+ return getDecl()->getType();
}
DefinedOrUnknownSVal getExtent(ValueManager& ValMgr) const;
@@ -758,7 +751,7 @@ class ObjCIvarRegion : public DeclRegion {
public:
const ObjCIvarDecl* getDecl() const { return cast<ObjCIvarDecl>(D); }
- QualType getValueType(ASTContext&) const { return getDecl()->getType(); }
+ QualType getValueType() const { return getDecl()->getType(); }
void dumpToStream(llvm::raw_ostream& os) const;
@@ -766,6 +759,30 @@ public:
return R->getKind() == ObjCIvarRegionKind;
}
};
+//===----------------------------------------------------------------------===//
+// Auxillary data classes for use with MemRegions.
+//===----------------------------------------------------------------------===//
+
+class ElementRegion;
+
+class RegionRawOffset {
+private:
+ friend class ElementRegion;
+
+ const MemRegion *Region;
+ int64_t Offset;
+
+ RegionRawOffset(const MemRegion* reg, int64_t offset = 0)
+ : Region(reg), Offset(offset) {}
+
+public:
+ // FIXME: Eventually support symbolic offsets.
+ int64_t getByteOffset() const { return Offset; }
+ const MemRegion *getRegion() const { return Region; }
+
+ void dumpToStream(llvm::raw_ostream& os) const;
+ void dump() const;
+};
class ElementRegion : public TypedRegion {
friend class MemRegionManager;
@@ -788,15 +805,15 @@ public:
SVal getIndex() const { return Index; }
- QualType getValueType(ASTContext&) const {
+ QualType getValueType() const {
return ElementType;
}
QualType getElementType() const {
return ElementType;
}
-
- RegionRawOffset getAsRawOffset() const;
+ /// Compute the offset within the array. The array might also be a subobject.
+ RegionRawOffset getAsArrayOffset() const;
void dumpToStream(llvm::raw_ostream& os) const;
@@ -820,7 +837,7 @@ class CXXObjectRegion : public TypedRegion {
Expr const *E, const MemRegion *sReg);
public:
- QualType getValueType(ASTContext& C) const {
+ QualType getValueType() const {
return Ex->getType();
}