[cfe-commits] r73376 - in /cfe/trunk: lib/Lex/Pragma.cpp test/Preprocessor/pragma_sysheader.c test/Preprocessor/pragma_sysheader.h

Chris Lattner sabre at nondot.org
Sun Jun 14 22:02:34 PDT 2009


Author: lattner
Date: Mon Jun 15 00:02:34 2009
New Revision: 73376

URL: http://llvm.org/viewvc/llvm-project?rev=73376&view=rev
Log:
Fix #pragma GCC system_header by making it insert a virtual linemarker into
the file at the point of the pragma.  This allows clang to know that all
sourcelocations after the pragma are in a system header.

Added:
    cfe/trunk/test/Preprocessor/pragma_sysheader.c
    cfe/trunk/test/Preprocessor/pragma_sysheader.h
Modified:
    cfe/trunk/lib/Lex/Pragma.cpp

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

==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Mon Jun 15 00:02:34 2009
@@ -195,8 +195,10 @@
 
 void Preprocessor::HandlePragmaMark() {
   assert(CurPPLexer && "No current lexer?");
-  if (CurLexer) CurLexer->ReadToEndOfLine();
-  else CurPTHLexer->DiscardToEndOfLine();
+  if (CurLexer)
+    CurLexer->ReadToEndOfLine();
+  else
+    CurPTHLexer->DiscardToEndOfLine();
 }
 
 
@@ -254,6 +256,18 @@
   // Mark the file as a system header.
   HeaderInfo.MarkFileSystemHeader(TheLexer->getFileEntry());
   
+  
+  PresumedLoc PLoc = SourceMgr.getPresumedLoc(SysHeaderTok.getLocation());
+  unsigned FilenameLen = strlen(PLoc.getFilename());
+  unsigned FilenameID = SourceMgr.getLineTableFilenameID(PLoc.getFilename(),
+                                                         FilenameLen);
+  
+  // Emit a line marker.  This will change any source locations from this point
+  // forward to realize they are in a system header.
+  // Create a line note with this information.
+  SourceMgr.AddLineNote(SysHeaderTok.getLocation(), PLoc.getLine(), FilenameID,
+                        false, false, true, false);
+  
   // Notify the client, if desired, that we are in a new source file.
   if (Callbacks)
     Callbacks->FileChanged(SysHeaderTok.getLocation(),

Added: cfe/trunk/test/Preprocessor/pragma_sysheader.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma_sysheader.c?rev=73376&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/pragma_sysheader.c (added)
+++ cfe/trunk/test/Preprocessor/pragma_sysheader.c Mon Jun 15 00:02:34 2009
@@ -0,0 +1,3 @@
+// RUN: clang -verify -pedantic %s -fsyntax-only
+// rdar://6899937
+#include "pragma_sysheader.h"

Added: cfe/trunk/test/Preprocessor/pragma_sysheader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pragma_sysheader.h?rev=73376&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/pragma_sysheader.h (added)
+++ cfe/trunk/test/Preprocessor/pragma_sysheader.h Mon Jun 15 00:02:34 2009
@@ -0,0 +1,4 @@
+#pragma GCC system_header
+typedef int x;
+typedef int x;
+





More information about the cfe-commits mailing list