@@ -2100,48 +2100,49 @@ std::pair<bool, bool> SourceManager::isInTheSameTranslationUnit(
2100
2100
2101
2101
// A location within a FileID on the path up from LOffs to the main file.
2102
2102
struct Entry {
2103
- unsigned Offset;
2104
- FileID ParentFID ; // Used for breaking ties.
2103
+ std::pair<FileID, unsigned > DecomposedLoc; // FileID redundant, but clearer.
2104
+ FileID ChildFID ; // Used for breaking ties. Invalid for the initial loc .
2105
2105
};
2106
2106
llvm::SmallDenseMap<FileID, Entry, 16 > LChain;
2107
2107
2108
- FileID Parent ;
2108
+ FileID LChild ;
2109
2109
do {
2110
- LChain.try_emplace (LOffs.first , Entry{LOffs. second , Parent });
2110
+ LChain.try_emplace (LOffs.first , Entry{LOffs, LChild });
2111
2111
// We catch the case where LOffs is in a file included by ROffs and
2112
2112
// quit early. The other way round unfortunately remains suboptimal.
2113
2113
if (LOffs.first == ROffs.first )
2114
2114
break ;
2115
- Parent = LOffs.first ;
2115
+ LChild = LOffs.first ;
2116
2116
} while (!MoveUpIncludeHierarchy (LOffs, *this ));
2117
2117
2118
- Parent = FileID () ;
2118
+ FileID RChild ;
2119
2119
do {
2120
- auto I = LChain.find (ROffs.first );
2121
- if (I != LChain.end ()) {
2120
+ auto LIt = LChain.find (ROffs.first );
2121
+ if (LIt != LChain.end ()) {
2122
2122
// Compare the locations within the common file and cache them.
2123
- LOffs. first = I-> first ;
2124
- LOffs. second = I ->second .Offset ;
2125
- // The relative order of LParent and RParent is a tiebreaker when
2123
+ LOffs = LIt-> second . DecomposedLoc ;
2124
+ LChild = LIt ->second .ChildFID ;
2125
+ // The relative order of LChild and RChild is a tiebreaker when
2126
2126
// - locs expand to the same location (occurs in macro arg expansion)
2127
2127
// - one loc is a parent of the other (we consider the parent as "first")
2128
- // For the parent to be first, the invalid file ID must compare smaller.
2128
+ // For the parent entry to be first, its invalid child file ID must
2129
+ // compare smaller to the valid child file ID of the other entry.
2129
2130
// However loaded FileIDs are <0, so we perform *unsigned* comparison!
2130
2131
// This changes the relative order of local vs loaded FileIDs, but it
2131
2132
// doesn't matter as these are never mixed in macro expansion.
2132
- unsigned LParent = I-> second . ParentFID .ID ;
2133
- unsigned RParent = Parent .ID ;
2133
+ unsigned LChildID = LChild .ID ;
2134
+ unsigned RChildID = RChild .ID ;
2134
2135
assert (((LOffs.second != ROffs.second ) ||
2135
- (LParent == 0 || RParent == 0 ) ||
2136
- isInSameSLocAddrSpace (getComposedLoc (I-> second . ParentFID , 0 ),
2137
- getComposedLoc (Parent , 0 ), nullptr )) &&
2136
+ (LChildID == 0 || RChildID == 0 ) ||
2137
+ isInSameSLocAddrSpace (getComposedLoc (LChild , 0 ),
2138
+ getComposedLoc (RChild , 0 ), nullptr )) &&
2138
2139
" Mixed local/loaded FileIDs with same include location?" );
2139
2140
IsBeforeInTUCache.setCommonLoc (LOffs.first , LOffs.second , ROffs.second ,
2140
- LParent < RParent );
2141
+ LChildID < RChildID );
2141
2142
return std::make_pair (
2142
2143
true , IsBeforeInTUCache.getCachedResult (LOffs.second , ROffs.second ));
2143
2144
}
2144
- Parent = ROffs.first ;
2145
+ RChild = ROffs.first ;
2145
2146
} while (!MoveUpIncludeHierarchy (ROffs, *this ));
2146
2147
2147
2148
// If we found no match, we're not in the same TU.
0 commit comments