summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-18 19:26:42 +0000
committerChris Lattner <sabre@nondot.org>2009-02-18 19:26:42 +0000
commit3dd56f96c385f78905ebc73bbbff56c2b4615d7d (patch)
tree82852880597ae24907dfeb87addc3959476aa52b
parentddb7191920f657397c27bc345037e9a92a232e6d (diff)
downloadbcm5719-llvm-3dd56f96c385f78905ebc73bbbff56c2b4615d7d.tar.gz
bcm5719-llvm-3dd56f96c385f78905ebc73bbbff56c2b4615d7d.zip
final string diagnostic issue (that I know about):
we used to not account for escapes in strings with string concat. Before: t.m:5:20: warning: field width should have type 'int', but argument has type 'unsigned int' printf("\n\n" "\n\n%*d", (unsigned) 1, 1); ^ ~~~~~~~~~~~~ after: t.m:5:23: warning: field width should have type 'int', but argument has type 'unsigned int' printf("\n\n" "\n\n%*d", (unsigned) 1, 1); ^ ~~~~~~~~~~~~ llvm-svn: 64941
-rw-r--r--clang/lib/Sema/SemaChecking.cpp19
1 files changed, 3 insertions, 16 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index b22932bb9a9..2f837822f86 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -32,8 +32,6 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
unsigned ByteNo) const {
assert(!SL->isWide() && "This doesn't work for wide strings yet");
- llvm::SmallString<16> 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;
@@ -64,21 +62,10 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
Token TheTok;
TheLexer.LexFromRawLexer(TheTok);
- // 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);
- }
+ // Use the StringLiteralParser to compute the length of the string in bytes.
+ StringLiteralParser SLP(&TheTok, 1, PP);
+ unsigned TokNumBytes = SLP.GetStringLength();
- // The length of the string is the token length minus the two quotes.
- TokNumBytes -= 2;
-
// If the byte is in this token, return the location of the byte.
if (ByteNo < TokNumBytes ||
(ByteNo == TokNumBytes && TokNo == SL->getNumConcatenated())) {
OpenPOWER on IntegriCloud