From f2e880a99c8b08976069331283392cc22b07701d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 20 Mar 2009 20:16:10 +0000 Subject: [PATCH] rename the buffer to to solve PR3849. Add a #include directive around the command line buffer so that diagnostics generated from -include directives get diagnostics like: In file included from :98: In file included from :3: ./t.h:2:1: warning: type specifier missing, defaults to 'int' b; ^ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67396 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/Preprocessor.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index b06050f984..811ea69760 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -642,8 +642,6 @@ static void InitializePredefinedMacros(Preprocessor &PP, // Get other target #defines. TI.getTargetDefines(PP.getLangOptions(), Buf); - - // FIXME: Should emit a #line directive here. } @@ -670,9 +668,18 @@ void Preprocessor::EnterMainSourceFile() { // Install things like __POWERPC__, __GNUC__, etc into the macro table. InitializePredefinedMacros(*this, PrologFile); - // Add on the predefines from the driver. + // Add on the predefines from the driver. Wrap in a #line directive to report + // that they come from the command line. + const char *LineDirective = "# 1 \"\" 1\n"; + PrologFile.insert(PrologFile.end(), + LineDirective, LineDirective+strlen(LineDirective)); + PrologFile.insert(PrologFile.end(), Predefines.begin(), Predefines.end()); + LineDirective = "# 2 \"\" 2\n"; + PrologFile.insert(PrologFile.end(), + LineDirective, LineDirective+strlen(LineDirective)); + // Memory buffer must end with a null byte! PrologFile.push_back(0); @@ -680,7 +687,7 @@ void Preprocessor::EnterMainSourceFile() { // PrologFile, preprocess it to populate the initial preprocessor state. llvm::MemoryBuffer *SB = llvm::MemoryBuffer::getMemBufferCopy(&PrologFile.front(),&PrologFile.back(), - ""); + ""); assert(SB && "Cannot fail to create predefined source buffer"); FileID FID = SourceMgr.createFileIDForMemBuffer(SB); assert(!FID.isInvalid() && "Could not create FileID for predefines?"); -- 2.40.0