================ @@ -751,12 +751,27 @@ std::string MemRegion::getDescriptiveName(bool UseQuotes) const { } // Get variable name. - if (R && R->canPrintPrettyAsExpr()) { - R->printPrettyAsExpr(os); - if (UseQuotes) - return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str(); - else + if (R) { + // MemRegion can be pretty printed. + if (R->canPrintPrettyAsExpr()) { + R->printPrettyAsExpr(os); + if (UseQuotes) + return (llvm::Twine("'") + os.str() + ArrayIndices + "'").str(); return (llvm::Twine(os.str()) + ArrayIndices).str(); + } + + // FieldRegion may have ElementRegion as SuperRegion. + if (const clang::ento::FieldRegion *FR = + R->getAs<clang::ento::FieldRegion>()) { + std::string Super = FR->getSuperRegion()->getDescriptiveName(false); + if (Super.empty()) + return ""; + + if (UseQuotes) + return (llvm::Twine("'") + Super + "." + FR->getDecl()->getName() + "'") + .str(); + return (llvm::Twine(Super) + "." + FR->getDecl()->getName()).str(); ---------------- steakhal wrote:
I wish we had a `singleQuote(const Twine &Subject)` function doing `('" + Subject + "'").str()` Along with: ``` auto QuoteIfNeeded = [UseQuotes](const Twine &Subject) { if (UseQuotes) return singleQuote(Subject); return Subject.str(); }; ``` Then you could do `QuoteIfNeeded(Super + "." + FR->getDecl()->getName())` etc. To make our life easier, we could `using llvm::Twine` at the top of this function to make it less verbose. https://github.com/llvm/llvm-project/pull/112313 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits