[PATCH] D34506: Relax an assert in the comparison of source locations

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 22 04:12:15 PDT 2017

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.




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 {

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34506.103552.patch
Type: text/x-patch
Size: 917 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170622/1d37ea35/attachment.bin>

More information about the cfe-commits mailing list