Skip to content

Commit 45c1f62

Browse files
authored
[SYCLomatic] Use ExpansionInfo instead of expansion location in the dpct::isLocationStraddle() (#2446)
Signed-off-by: Jiang, Zhiwei <[email protected]>
1 parent 491de11 commit 45c1f62

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

clang/lib/DPCT/Utility.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,12 +1698,20 @@ bool isLocationStraddle(SourceLocation BeginLoc, SourceLocation EndLoc) {
16981698

16991699
// Different expansion but same define, e.g. AAA * AAA
17001700
if (BeginLoc.isMacroID() && EndLoc.isMacroID()) {
1701-
auto ExpansionBegin = SM.getExpansionRange(BeginLoc).getBegin();
1702-
auto ExpansionEnd = SM.getExpansionRange(EndLoc).getBegin();
1703-
auto DLExpanBegin = SM.getDecomposedLoc(ExpansionBegin);
1704-
auto DLExpanEnd = SM.getDecomposedLoc(ExpansionEnd);
1705-
if (DLExpanBegin.first != DLExpanEnd.first ||
1706-
DLExpanBegin.second != DLExpanEnd.second) {
1701+
std::pair<FileID, unsigned> BeginLocInfo = SM.getDecomposedLoc(BeginLoc);
1702+
std::pair<FileID, unsigned> EndLocInfo = SM.getDecomposedLoc(EndLoc);
1703+
SrcMgr::ExpansionInfo BeginExpInfo =
1704+
SM.getSLocEntry(BeginLocInfo.first).getExpansion();
1705+
SrcMgr::ExpansionInfo EndExpInfo =
1706+
SM.getSLocEntry(EndLocInfo.first).getExpansion();
1707+
// Since different expansions should have different ExpansionInfo instances,
1708+
// we use all the members (except SpellingLoc) in ExpansionInfo to do this
1709+
// check.
1710+
if (BeginExpInfo.getExpansionLocStart() !=
1711+
EndExpInfo.getExpansionLocStart() ||
1712+
BeginExpInfo.getExpansionLocEnd() != EndExpInfo.getExpansionLocEnd() ||
1713+
BeginExpInfo.isExpansionTokenRange() !=
1714+
EndExpInfo.isExpansionTokenRange()) {
17071715
return true;
17081716
}
17091717
}

0 commit comments

Comments
 (0)