Index: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h =================================================================== --- include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h +++ include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h @@ -176,6 +176,11 @@ /// as part of a larger expression. virtual bool canPrintPrettyAsExpr() const; + /// \brief In case this region is a region of a variable or an element region, + /// this method will return the name of the variable. Otherwise it will return + /// an empty StringRef. + StringRef getVariableName() const; + /// \brief Print the region as expression. /// /// When this region represents a subexpression, the method is for printing Index: lib/StaticAnalyzer/Core/MemRegion.cpp =================================================================== --- lib/StaticAnalyzer/Core/MemRegion.cpp +++ lib/StaticAnalyzer/Core/MemRegion.cpp @@ -573,6 +573,19 @@ return false; } +StringRef MemRegion::getVariableName() const { + const MemRegion *reg = this; + while (const auto *ereg = dyn_cast(reg)) + reg = ereg->getSuperRegion(); + const auto *vreg = dyn_cast(reg); + if (!vreg) + return ""; + const auto *nd = dyn_cast(vreg->getDecl()); + if (!nd) + return ""; + return nd->getName(); +} + void MemRegion::printPretty(raw_ostream &os) const { assert(canPrintPretty() && "This region cannot be printed pretty."); os << "'";