Skip to content

Commit 73d1602

Browse files
authored
[clang][Tooling] Fix getFileRange returning a range spanning macro invocation (#169842)
A followup to 4099121. When the start or end token is inside a macro argument and the other is outside of the macro, we want to reject the range for a similar reason. The range will include half of the macro call, either the closing paren or the macro name and open paren.
1 parent 8c31b12 commit 73d1602

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

clang/lib/Tooling/Transformer/SourceCode.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,7 @@ static bool spelledInMacroDefinition(CharSourceRange Range,
114114
return B.isInvalid() || B != E;
115115
}
116116

117-
if (Range.getBegin().isMacroID())
118-
return getMacroArgumentSpellingLoc(Range.getBegin(), SM).isInvalid();
119-
if (Range.getEnd().isMacroID())
120-
return getMacroArgumentSpellingLoc(Range.getEnd(), SM).isInvalid();
121-
122-
return false;
117+
return Range.getBegin().isMacroID() || Range.getEnd().isMacroID();
123118
}
124119

125120
// Returns the expansion char-range of `Loc` if `Loc` is a split token. For

clang/unittests/Tooling/SourceCodeTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,13 @@ TEST(SourceCodeTest, EditInvolvingExpansionIgnoringExpansionShouldFail) {
511511
#define M2(x, y) x ## y
512512
#define M3(x) foobar(x)
513513
#define M4(x, y) x y
514+
#define M5(x) x
514515
int foobar(int);
515516
int a = M1(foobar);
516517
int b = M2(foo, bar(2));
517518
int c = M3(3);
518519
int d = M4(foobar, (4));
520+
int e = M5(foobar) (5);
519521
)cpp");
520522

521523
CallsVisitor Visitor;

0 commit comments

Comments
 (0)