aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-18 19:21:10 +0000
committerChris Lattner <sabre@nondot.org>2009-02-18 19:21:10 +0000
commit719e61573f27c11057ecfe0dd8f141621602c571 (patch)
treeaaaa50387e651a10f865c907286f61b21ad3a70f /lib/Sema/SemaChecking.cpp
parent6dcf63e920e003ea73cff332492dc11690b100a6 (diff)
Next step toward making string diagnostics correct: handle
escapes in the string for subtoken positioning. This gives us working examples like: t.m:5:16: warning: field width should have type 'int', but argument has type 'unsigned int' printf("\n\n%*d", (unsigned) 1, 1); ^ ~~~~~~~~~~~~ where before the caret pointed two spaces to the left. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64940 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r--lib/Sema/SemaChecking.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 38cc427a00..b22932bb9a 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -17,6 +17,7 @@
#include "clang/AST/DeclObjC.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/ExprObjC.h"
+#include "clang/Lex/LiteralSupport.h"
#include "clang/Lex/Preprocessor.h"
using namespace clang;
@@ -31,7 +32,7 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
unsigned ByteNo) const {
assert(!SL->isWide() && "This doesn't work for wide strings yet");
- llvm::SmallString<32> SpellingBuffer;
+ 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.
@@ -78,13 +79,15 @@ SourceLocation Sema::getLocationOfStringLiteralByte(const StringLiteral *SL,
// The length of the string is the token length minus the two quotes.
TokNumBytes -= 2;
- // FIXME: This should consider character escapes!
-
// If the byte is in this token, return the location of the byte.
if (ByteNo < TokNumBytes ||
(ByteNo == TokNumBytes && TokNo == SL->getNumConcatenated())) {
- // We advance +1 to step over the '"'.
- return PP.AdvanceToTokenCharacter(StrTokLoc, ByteNo+1);
+ unsigned Offset =
+ StringLiteralParser::getOffsetOfStringByte(TheTok, ByteNo, PP);
+
+ // Now that we know the offset of the token in the spelling, use the
+ // preprocessor to get the offset in the original source.
+ return PP.AdvanceToTokenCharacter(StrTokLoc, Offset);
}
// Move to the next string token.