[PATCH] D18309: sourceRange function for MemRegion
Alexander Droste via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 21 03:15:51 PDT 2016
Alexander_Droste created this revision.
Alexander_Droste added a reviewer: zaks.anna.
Alexander_Droste added subscribers: dcoughlin, xazax.hun, cfe-commits.
Retrieve source range from memory region. The range retrieval is based on the decl obtained from the memory region.
http://reviews.llvm.org/D18309
Files:
include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
lib/StaticAnalyzer/Core/MemRegion.cpp
Index: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===================================================================
--- include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -150,6 +150,18 @@
template<typename RegionTy> const RegionTy* getAs() const;
virtual bool isBoundable() const { return false; }
+
+ /// Retrieve source range from memory region. The range retrieval
+ /// is based on the decl obtained from the memory region.
+ /// For a VarRegion the range of the base region is returned.
+ /// For a FieldRegion the range of the field is returned.
+ /// If no declaration is found, an empty source range is returned.
+ /// The client is responsible for checking if the returned range is valid.
+ ///
+ /// \param MR memory region to retrieve the source range for
+ ///
+ /// \returns source range for declaration retrieved from memory region
+ clang::SourceRange sourceRange() const;
};
/// MemSpaceRegion - A memory region that represents a "memory space";
Index: lib/StaticAnalyzer/Core/MemRegion.cpp
===================================================================
--- lib/StaticAnalyzer/Core/MemRegion.cpp
+++ lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -632,6 +632,25 @@
superRegion->printPrettyAsExpr(os);
}
+SourceRange MemRegion::sourceRange() const {
+ const VarRegion *const VR = dyn_cast<VarRegion>(this->getBaseRegion());
+ const FieldRegion *const FR = dyn_cast<FieldRegion>(this);
+
+ // Check for more specific regions first.
+ // FieldRegion
+ if (FR) {
+ return FR->getDecl()->getSourceRange();
+ }
+ // VarRegion
+ else if (VR) {
+ return VR->getDecl()->getSourceRange();
+ }
+ // Return invalid source range (can be checked by client).
+ else {
+ return SourceRange{};
+ }
+}
+
//===----------------------------------------------------------------------===//
// MemRegionManager methods.
//===----------------------------------------------------------------------===//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18309.51143.patch
Type: text/x-patch
Size: 2041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160321/1bd972f7/attachment.bin>
More information about the cfe-commits
mailing list