xazax.hun created this revision. Right now source locations from different translation units can not be compared. This is a problem for an upcoming feature in the Static Analyzer, the cross translation unit support (https://reviews.llvm.org/D30691).
It would be great to be able to sort the source locations, even if there are no guarantee to have a meaningful order between source locations from different translation units. Repository: rL LLVM https://reviews.llvm.org/D34506 Files: lib/Basic/SourceManager.cpp Index: lib/Basic/SourceManager.cpp =================================================================== --- lib/Basic/SourceManager.cpp +++ lib/Basic/SourceManager.cpp @@ -2034,6 +2034,9 @@ } /// \brief Determines the order of 2 source locations in the translation unit. +/// It also works when two locations are from different translation +/// units. In that case it will return *some* order, that is +/// deterministic for that invocation of the compiler. /// /// \returns true if LHS source location comes before RHS, false otherwise. bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, @@ -2130,7 +2133,8 @@ return LIsScratch; return LOffs.second < ROffs.second; } - llvm_unreachable("Unsortable locations found"); + // Source locations from different translation units. + return LOffs.first < ROffs.first; } void SourceManager::PrintStats() const {
Index: lib/Basic/SourceManager.cpp =================================================================== --- lib/Basic/SourceManager.cpp +++ lib/Basic/SourceManager.cpp @@ -2034,6 +2034,9 @@ } /// \brief Determines the order of 2 source locations in the translation unit. +/// It also works when two locations are from different translation +/// units. In that case it will return *some* order, that is +/// deterministic for that invocation of the compiler. /// /// \returns true if LHS source location comes before RHS, false otherwise. bool SourceManager::isBeforeInTranslationUnit(SourceLocation LHS, @@ -2130,7 +2133,8 @@ return LIsScratch; return LOffs.second < ROffs.second; } - llvm_unreachable("Unsortable locations found"); + // Source locations from different translation units. + return LOffs.first < ROffs.first; } void SourceManager::PrintStats() const {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits