]> granicus.if.org Git - clang/commitdiff
do not use "1" for line marker for the main file
authorLubos Lunak <l.lunak@centrum.cz>
Thu, 1 May 2014 13:50:44 +0000 (13:50 +0000)
committerLubos Lunak <l.lunak@centrum.cz>
Thu, 1 May 2014 13:50:44 +0000 (13:50 +0000)
"1" means entering a new file (from a different one), but the main
file is not included from anything (and this would e.g. confuse -Wunused-macros
to not report unused macros in the main file, see pr15610, or also see pr18948).
The line marker is still useful e.g. if the resulting file is renamed or used
via a pipe.

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

lib/Rewrite/Frontend/InclusionRewriter.cpp
test/Frontend/rewrite-includes.c

index 4a7d69c26aa6244e5202f9699a6cf0dad9afc480..ad8328e7ca12d1035fa2c8b24ffea40f31f980b0 100644 (file)
@@ -352,8 +352,11 @@ bool InclusionRewriter::Process(FileID FileId,
 
   StringRef EOL = DetectEOL(FromFile);
 
-  // Per the GNU docs: "1" indicates the start of a new file.
-  WriteLineInfo(FileName, 1, FileType, EOL, " 1");
+  // Per the GNU docs: "1" indicates entering a new file.
+  if (FileId == SM.getMainFileID())
+    WriteLineInfo(FileName, 1, FileType, EOL, "");
+  else
+    WriteLineInfo(FileName, 1, FileType, EOL, " 1");
 
   if (SM.getFileIDSize(FileId) == 0)
     return false;
index 2158dd0e8ead5dfbed6895982ca1811eb17f7bf9..619d34a22d2ffe1d0b36316671e4040080747219 100644 (file)
@@ -21,6 +21,7 @@ A(1,2)
 #include "rewrite-includes7.h"
 #include "rewrite-includes8.h"
 // ENDCOMPARE
+// CHECK: {{^}}# 1 "{{.*}}rewrite-includes.c"{{$}}
 // CHECK: {{^}}// STARTCOMPARE{{$}}
 // CHECK-NEXT: {{^}}#define A(a,b) a ## b{{$}}
 // CHECK-NEXT: {{^}}A(1,2){{$}}