On Monday 01 of July 2013, Eli Friedman wrote:
> On Sat, Jun 29, 2013 at 11:59 PM, Lubos Lunak <[email protected]> wrote:
> >   Hello,
> >
> >  could somebody please review and commit the atached patch for pr15610?
> > Thank
> > you.
>
> Does this same issue apply to other users of
> Preprocessor::isInPrimaryFile() and/or SourceManager::isFromMainFile()?
>  (For example, Preprocessor::HandlePragmaOnce.)  If so, can you please add
> a common helper routine in SourceManager?

 I see you have fixed this meanwhile, but I've noticed that now 
isFromMainFile() is always false for any -frewrite-includes output, since it 
always writes out line markers even for entering the main file. This is not 
necessary and technically it's probably also wrong, so the attached patch 
should fix that. Ok to commit?

-- 
 Lubos Lunak
From f5d9b59510cdc666d134dba8c3b7edf40ff0e698 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= <[email protected]>
Date: Wed, 27 Nov 2013 14:43:16 +0100
Subject: [PATCH] do not write line markers for main file in -frewrite-includes
 (pr15610)

Entering any file (according to line markers) makes
SourceManager::isInMainFile() return false, so avoid unnecesary line markers
for the main file.
---
 lib/Rewrite/Frontend/InclusionRewriter.cpp | 3 ++-
 test/Frontend/rewrite-includes.c           | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/Rewrite/Frontend/InclusionRewriter.cpp b/lib/Rewrite/Frontend/InclusionRewriter.cpp
index bd4250a..baab7bf 100644
--- a/lib/Rewrite/Frontend/InclusionRewriter.cpp
+++ b/lib/Rewrite/Frontend/InclusionRewriter.cpp
@@ -358,7 +358,8 @@ 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");
+  if (FileId != PP.getPredefinesFileID() && FileId != SM.getMainFileID())
+    WriteLineInfo(FileName, 1, FileType, EOL, " 1");
 
   if (SM.getFileIDSize(FileId) == 0)
     return false;
diff --git a/test/Frontend/rewrite-includes.c b/test/Frontend/rewrite-includes.c
index 2158dd0..80f6693 100644
--- a/test/Frontend/rewrite-includes.c
+++ b/test/Frontend/rewrite-includes.c
@@ -21,6 +21,9 @@ A(1,2)
 #include "rewrite-includes7.h"
 #include "rewrite-includes8.h"
 // ENDCOMPARE
+
+// CHECK-NOT: {{^}}# 1 "<built-in>" 1{{$}}
+// CHECK-NOT: {{^}}# 1 "{{.*}}rewrite-includes.c" 1{{$}}
 // CHECK: {{^}}// STARTCOMPARE{{$}}
 // CHECK-NEXT: {{^}}#define A(a,b) a ## b{{$}}
 // CHECK-NEXT: {{^}}A(1,2){{$}}
-- 
1.8.1.4

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to