This patch removes the necessity to access the SourceLocation internal
representation in several places that use FoldingSet objects.
Seems a bit strange to me to add SourceLocation::Profile. Is there another hook available for FoldingSet that works with free functions, or template specializations? You could make that hook a friend in order to give it access to the internals. Or can the caller just use getHashValue()?
I'm not sure you need this change since you don't need to give access to internals here.
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.