summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f469684e503..6ffca1b7b87 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -31,6 +31,8 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
unsigned ByteNo) const {
assert(!SL->isWide() && "This doesn't work for wide strings yet");
+ llvm::SmallString<32> SpellingBuffer;
+
// Loop over all of the tokens in this string until we find the one that
// contains the byte we're looking for.
unsigned TokNo = 0;
@@ -61,8 +63,13 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
Token TheTok;
TheLexer.LexFromRawLexer(TheTok);
+ // Get the spelling of the token to remove trigraphs and escaped newlines.
+ SpellingBuffer.resize(TheTok.getLength());
+ const char *SpellingPtr = &SpellingBuffer[0];
+ unsigned TokLen = PP.getSpelling(TheTok, SpellingPtr);
+
// The length of the string is the token length minus the two quotes.
- unsigned TokNumBytes = TheTok.getLength()-2;
+ unsigned TokNumBytes = TokLen-2;
// If we found the token we're looking for, return the location.
// FIXME: This should consider character escapes!
OpenPOWER on IntegriCloud