Skip to content

Commit 14bd903

Browse files
committed
Handle source ranges where isTokenRange() == true (the end of this range specifies the start of the last token). In this case, compute the source location just past the end of the token at this source location. Fix the test. The end column is not exclusive.
1 parent 1525fe8 commit 14bd903

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

clang/lib/Frontend/FrontendAction.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,12 @@ class DeserializedDeclsLineRangePrinter : public ASTConsumer,
130130
if (!R.isValid())
131131
continue;
132132

133+
SourceLocation End = R.getEnd();
134+
if (R.isTokenRange())
135+
End = Lexer::getLocForEndOfToken(End, 0, SM, D->getLangOpts());
136+
133137
auto *F = SM.getFileEntryForID(SM.getFileID(R.getBegin()));
134-
if (F != SM.getFileEntryForID(SM.getFileID(R.getEnd()))) {
138+
if (F != SM.getFileEntryForID(SM.getFileID(End))) {
135139
// Such cases are rare and difficult to handle.
136140
continue;
137141
}
@@ -140,7 +144,7 @@ class DeserializedDeclsLineRangePrinter : public ASTConsumer,
140144
if (!Data.Ref)
141145
Data.Ref = SM.getFileEntryRefForID(SM.getFileID(R.getBegin()));
142146
Data.FromTo.push_back({Position::GetSpelling(SM, R.getBegin()),
143-
Position::GetSpelling(SM, R.getEnd())});
147+
Position::GetSpelling(SM, End)});
144148
}
145149

146150
// To simplify output, merge consecutive and intersecting ranges.

clang/test/Frontend/dump-deserialized-declaration-ranges.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// RUN: split-file %s %t
44
// RUN: %clang_cc1 -xc++ -fmodules -fmodule-name=foo -fmodule-map-file=%t/foo.cppmap -emit-module %t/foo.cppmap -o %t/foo.pcm
55
// RUN: %clang_cc1 -xc++ -fmodules -dump-deserialized-declaration-ranges=%t/decls -fmodule-file=%t/foo.pcm %t/foo.cpp -o %t/foo.o
6+
// RUN: cat %t/decls
67
// RUN: cat %t/decls | FileCheck -check-prefix=RANGE %s
78
// RANGE:{
89
// RANGE-NEXT: "required_ranges": [
@@ -16,7 +17,7 @@
1617
// RANGE-NEXT: },
1718
// RANGE-NEXT: "to": {
1819
// RANGE-NEXT: "line": 9,
19-
// RANGE-NEXT: "column": 1
20+
// RANGE-NEXT: "column": 2
2021
// RANGE-NEXT: }
2122
// RANGE-NEXT: },
2223
// RANGE-NEXT: {
@@ -26,7 +27,7 @@
2627
// RANGE-NEXT: },
2728
// RANGE-NEXT: "to": {
2829
// RANGE-NEXT: "line": 11,
29-
// RANGE-NEXT: "column": 12
30+
// RANGE-NEXT: "column": 24
3031
// RANGE-NEXT: }
3132
// RANGE-NEXT: },
3233
// RANGE-NEXT: {
@@ -36,7 +37,7 @@
3637
// RANGE-NEXT: },
3738
// RANGE-NEXT: "to": {
3839
// RANGE-NEXT: "line": 15,
39-
// RANGE-NEXT: "column": 1
40+
// RANGE-NEXT: "column": 2
4041
// RANGE-NEXT: }
4142
// RANGE-NEXT: }
4243
// RANGE-NEXT: ]

0 commit comments

Comments
 (0)