summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaChecking.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 6ffca1b7b87..818a892617e 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -63,13 +63,20 @@ 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);
+ // We generally care about the length of the token, which is known by the
+ // lexer as long as we don't need to clean it (trigraphs/newlines).
+ unsigned TokNumBytes;
+ if (!TheTok.needsCleaning()) {
+ TokNumBytes = TheTok.getLength();
+ } else {
+ // Get the spelling of the token to remove trigraphs and escaped newlines.
+ SpellingBuffer.resize(TheTok.getLength());
+ const char *SpellingPtr = &SpellingBuffer[0];
+ TokNumBytes = PP.getSpelling(TheTok, SpellingPtr);
+ }
// The length of the string is the token length minus the two quotes.
- unsigned TokNumBytes = TokLen-2;
+ TokNumBytes -= 2;
// If we found the token we're looking for, return the location.
// FIXME: This should consider character escapes!
OpenPOWER on IntegriCloud