[cfe-commits] r67396 - /cfe/trunk/lib/Lex/Preprocessor.cpp

Chris Lattner sabre at nondot.org
Fri Mar 20 13:16:10 PDT 2009


Author: lattner
Date: Fri Mar 20 15:16:10 2009
New Revision: 67396

URL: http://llvm.org/viewvc/llvm-project?rev=67396&view=rev
Log:
rename the <predefines> buffer to <built-in> 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 <built-in>:98:
In file included from <command line>:3:
./t.h:2:1: warning: type specifier missing, defaults to 'int'
b;
^


Modified:
    cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=67396&r1=67395&r2=67396&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Fri Mar 20 15:16:10 2009
@@ -642,8 +642,6 @@
   
   // Get other target #defines.
   TI.getTargetDefines(PP.getLangOptions(), Buf);
-  
-  // FIXME: Should emit a #line directive here.
 }
 
 
@@ -670,9 +668,18 @@
   // 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 \"<command line>\" 1\n";
+  PrologFile.insert(PrologFile.end(),
+                    LineDirective, LineDirective+strlen(LineDirective));
+  
   PrologFile.insert(PrologFile.end(), Predefines.begin(), Predefines.end());
   
+  LineDirective = "# 2 \"<built-in>\" 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 @@
   // PrologFile, preprocess it to populate the initial preprocessor state.
   llvm::MemoryBuffer *SB = 
     llvm::MemoryBuffer::getMemBufferCopy(&PrologFile.front(),&PrologFile.back(),
-                                         "<predefines>");
+                                         "<built-in>");
   assert(SB && "Cannot fail to create predefined source buffer");
   FileID FID = SourceMgr.createFileIDForMemBuffer(SB);
   assert(!FID.isInvalid() && "Could not create FileID for predefines?");





More information about the cfe-commits mailing list