]> granicus.if.org Git - clang/commitdiff
The Lexer constructor expects a source location at the start of the
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 11 May 2012 21:39:18 +0000 (21:39 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 11 May 2012 21:39:18 +0000 (21:39 +0000)
file buffer, not at the start of lexing.

Fixes assertion hit in format diagnostics. rdar://11418366

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156647 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
test/PCH/format-strings.c [new file with mode: 0644]

index afc7410a81edd9a772c1fc891369dcb1bf753068..ba2cc8eb342936fb1bb3c1f84357b58fd71cecf6 100644 (file)
@@ -708,8 +708,8 @@ getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
     LangOpts.Trigraphs = true;
     
     // Create a lexer starting at the beginning of this token.
-    Lexer TheLexer(StrTokSpellingLoc, Features, Buffer.begin(), StrData,
-                   Buffer.end());
+    Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), Features,
+                   Buffer.begin(), StrData, Buffer.end());
     Token TheTok;
     TheLexer.LexFromRawLexer(TheTok);
     
index 629f1eab43567c937f4fe9cdbdb8e5e6581b1aee..f1ce8786a1f81ec422b5d2250c6946eaa65799b0 100644 (file)
@@ -441,9 +441,10 @@ void HTMLDiagnostics::HandlePiece(Rewriter& R, FileID BugFileID,
       FullSourceLoc L = MP->getLocation().asLocation().getExpansionLoc();
       assert(L.isFileID());
       StringRef BufferInfo = L.getBufferData();
-      const char* MacroName = L.getDecomposedLoc().second + BufferInfo.data();
-      Lexer rawLexer(L, PP.getLangOpts(), BufferInfo.begin(),
-                     MacroName, BufferInfo.end());
+      std::pair<FileID, unsigned> LocInfo = L.getDecomposedLoc();
+      const char* MacroName = LocInfo.second + BufferInfo.data();
+      Lexer rawLexer(SM.getLocForStartOfFile(LocInfo.first), PP.getLangOpts(),
+                     BufferInfo.begin(), MacroName, BufferInfo.end());
 
       Token TheTok;
       rawLexer.LexFromRawLexer(TheTok);
diff --git a/test/PCH/format-strings.c b/test/PCH/format-strings.c
new file mode 100644 (file)
index 0000000..7198c4d
--- /dev/null
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -D FOOBAR="\"\"" %s -emit-pch -o %t.pch
+// RUN: %clang_cc1 -D FOOBAR="\"\"" %s -include-pch %t.pch
+
+// rdar://11418366
+
+#ifndef HEADER
+#define HEADER
+
+extern int printf(const char *restrict, ...);
+#define LOG printf(FOOBAR "%f", __LINE__)
+
+#else
+
+void foo() {
+  LOG;
+}
+
+#endif