[PATCH] D69844: [clang][Basic] Integrate SourceLocation with FoldingSet, NFCI

Duncan P. N. Exon Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 08:37:53 PDT 2020


dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM.



================
Comment at: clang/lib/Analysis/PathDiagnostic.cpp:1088
+  ID.Add(Range.getEnd());
+  ID.Add(static_cast<const SourceLocation &>(Loc));
 }
----------------
miyuki wrote:
> dexonsmith wrote:
> > I'm surprised you need this `static_cast`, can you explain why it was necessary?
> `Loc` is an object of type `FullSourceLoc`, a class derived from `SourceLocation`. When the `FoldingSetNodeID::Add` template method is called with `Loc` it tries to instantiate `FoldingSetTrait<FullSourceLoc>` and fails (because there is no explicit specialization for `FullSourceLoc` and the default one relies on the method `FullSourceLoc::Profile` which does not exist). `FullSourceLoc` does not contain any additional information about the location itself (it just holds a pointer to the associated `SourceManager`), so there is no need to specialize `FoldingSetTrait` for it, and casting to `SourceLocation` will make `FoldingSetNodeID::Add` use the correct `FoldingSetTrait` specialization.
Right, that makes sense. Thanks for explaining!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69844/new/

https://reviews.llvm.org/D69844



More information about the cfe-commits mailing list