Skip to content

Commit 4a9007c

Browse files
committedApr 5, 2019
Revert "[Lexer] NFC: Fix an off-by-one bug in getAsCharRange()."
This reverts commit r357823. Was breaking clang-tidy! Differential Revision: https://reviews.llvm.org/D59977 llvm-svn: 357827
1 parent cb70fe1 commit 4a9007c

File tree

3 files changed

+2
-25
lines changed

3 files changed

+2
-25
lines changed
 

Diff for: ‎clang/include/clang/Basic/PlistSupport.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,7 @@ inline void EmitRange(raw_ostream &o, const SourceManager &SM,
127127
assert(R.isCharRange() && "cannot handle a token range");
128128
Indent(o, indent) << "<array>\n";
129129
EmitLocation(o, SM, R.getBegin(), FM, indent + 1);
130-
131-
// The ".getLocWithOffset(-1)" emulates the behavior of an off-by-one bug
132-
// in Lexer that is already fixed. It is here for backwards compatibility
133-
// even though it is incorrect.
134-
EmitLocation(o, SM, R.getEnd().getLocWithOffset(-1), FM, indent + 1);
130+
EmitLocation(o, SM, R.getEnd(), FM, indent + 1);
135131
Indent(o, indent) << "</array>\n";
136132
}
137133

Diff for: ‎clang/include/clang/Lex/Lexer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ class Lexer : public PreprocessorLexer {
382382
SourceLocation End = getLocForEndOfToken(Range.getEnd(), 0, SM, LangOpts);
383383
return End.isInvalid() ? CharSourceRange()
384384
: CharSourceRange::getCharRange(
385-
Range.getBegin(), End);
385+
Range.getBegin(), End.getLocWithOffset(-1));
386386
}
387387
static CharSourceRange getAsCharRange(CharSourceRange Range,
388388
const SourceManager &SM,

Diff for: ‎clang/unittests/Lex/LexerTest.cpp

-19
Original file line numberDiff line numberDiff line change
@@ -513,23 +513,4 @@ TEST_F(LexerTest, StringizingRasString) {
513513
EXPECT_EQ(String6, R"(a\\\n\n\n \\\\b)");
514514
}
515515

516-
TEST_F(LexerTest, CharRangeOffByOne) {
517-
std::vector<Token> toks = Lex(R"(#define MOO 1
518-
void foo() { MOO; })");
519-
const Token &moo = toks[5];
520-
521-
EXPECT_EQ(getSourceText(moo, moo), "MOO");
522-
523-
SourceRange R{moo.getLocation(), moo.getLocation()};
524-
525-
EXPECT_TRUE(
526-
Lexer::isAtStartOfMacroExpansion(R.getBegin(), SourceMgr, LangOpts));
527-
EXPECT_TRUE(
528-
Lexer::isAtEndOfMacroExpansion(R.getEnd(), SourceMgr, LangOpts));
529-
530-
CharSourceRange CR = Lexer::getAsCharRange(R, SourceMgr, LangOpts);
531-
532-
EXPECT_EQ(Lexer::getSourceText(CR, SourceMgr, LangOpts), "MOO"); // Was "MO".
533-
}
534-
535516
} // anonymous namespace

0 commit comments

Comments
 (0)
Please sign in to comment.