[cfe-commits] r140131 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h lib/StaticAnalyzer/Core/PathDiagnostic.cpp

Ted Kremenek kremenek at apple.com
Mon Sep 19 23:27:54 PDT 2011


On Sep 19, 2011, at 6:51 PM, Anna Zaks wrote:

> +  FullSourceLoc genLocation(const ParentMap *PM=0) const;
> +  PathDiagnosticRange genRange(const ParentMap *PM=0) const;


Hi Anna,

Instead of passing the ParentMap, how about having genLocation() lazily query LocationContext for one?  That way it only gets created when we need it.

Actually, it it looks like we are still using the LC member variable in genRange(), instead of the passed ParentMap:

        case Stmt::ObjCForCollectionStmtClass: {
          SourceLocation L = getValidSourceLocation(S, LC->getParentMap());
          return SourceRange(L, L);

Since LocationContext isn't guaranteed to live for the lifetime of PathDiagnosticLocation, I suggest:

1) Remove the LC member variable (fix potential use-after-free).
2) Pass (possibly null?) LocationContext * to genLocation() and genRange()
3) Lazily query that LocationContext for a ParentMap as needed.  LocationContext (or really, AnalysisContext) will make sure the ParentMap is constructed once.

What do you think?

Cheers,
Ted
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110919/d2a7ee78/attachment.html>


More information about the cfe-commits mailing list