[cfe-commits] r168128 - in /cfe/trunk: lib/Frontend/PrintPreprocessedOutput.cpp test/Preprocessor/line-directive-output.c

Daniel Dunbar daniel at zuster.org
Thu Nov 15 17:51:11 PST 2012


Author: ddunbar
Date: Thu Nov 15 19:51:11 2012
New Revision: 168128

URL: http://llvm.org/viewvc/llvm-project?rev=168128&view=rev
Log:
CPP Output: Do not emit an enter file marker for the main file.

 - This diverges from gcc, and confuses tools (like dtrace) which track # line
   markers as a way to determine which content is in the context of the main
   file.

Modified:
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
    cfe/trunk/test/Preprocessor/line-directive-output.c

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=168128&r1=168127&r2=168128&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Thu Nov 15 19:51:11 2012
@@ -95,6 +95,7 @@
   bool DisableLineMarkers;
   bool DumpDefines;
   bool UseLineDirective;
+  bool IsFirstFileEntered;
 public:
   PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os,
                            bool lineMarkers, bool defines)
@@ -107,6 +108,7 @@
     EmittedDirectiveOnThisLine = false;
     FileType = SrcMgr::C_User;
     Initialized = false;
+    IsFirstFileEntered = false;
 
     // If we're in microsoft mode, use normal #line instead of line markers.
     UseLineDirective = PP.getLangOpts().MicrosoftExt;
@@ -273,6 +275,15 @@
     Initialized = true;
   }
 
+  // Do not emit an enter marker for the main file (which we expect is the first
+  // entered file). This matches gcc, and improves compatibility with some tools
+  // which track the # line markers as a way to determine when the preprocessed
+  // output is in the context of the main file.
+  if (Reason == PPCallbacks::EnterFile && !IsFirstFileEntered) {
+    IsFirstFileEntered = true;
+    return;
+  }
+
   switch (Reason) {
   case PPCallbacks::EnterFile:
     WriteLineInfo(CurLine, " 1", 2);

Modified: cfe/trunk/test/Preprocessor/line-directive-output.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/line-directive-output.c?rev=168128&r1=168127&r2=168128&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/line-directive-output.c (original)
+++ cfe/trunk/test/Preprocessor/line-directive-output.c Thu Nov 15 19:51:11 2012
@@ -2,6 +2,10 @@
 // PR6101
 int a;
 // CHECK: # 1 "{{.*}}line-directive-output.c"
+
+// Check that we do not emit an enter marker for the main file.
+// CHECK-NOT: # 1 "{{.*}}line-directive-output.c" 1
+
 // CHECK: int a;
 
 // CHECK-NEXT: # 50 "{{.*}}line-directive-output.c"





More information about the cfe-commits mailing list