Prechádzať zdrojové kódy

do not use "1" for line marker for the predefines "file" either

Similar to r207764.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207794 91177308-0d34-0410-b5e6-96231b3b80d8
Lubos Lunak 11 rokov pred
rodič
commit
13c23baecc

+ 5 - 1
lib/Rewrite/Frontend/InclusionRewriter.cpp

@@ -250,6 +250,10 @@ void InclusionRewriter::CommentOutDirective(Lexer &DirectiveLex,
   do {
     DirectiveLex.LexFromRawLexer(DirectiveToken);
   } while (!DirectiveToken.is(tok::eod) && DirectiveToken.isNot(tok::eof));
+  if (&FromFile == PredefinesBuffer) {
+    // OutputContentUpTo() would not output anything anyway.
+    return;
+  }
   OS << "#if 0 /* expanded by -frewrite-includes */" << EOL;
   OutputContentUpTo(FromFile, NextToWrite,
     SM.getFileOffset(DirectiveToken.getLocation()) + DirectiveToken.getLength(),
@@ -353,7 +357,7 @@ bool InclusionRewriter::Process(FileID FileId,
   StringRef EOL = DetectEOL(FromFile);
 
   // Per the GNU docs: "1" indicates entering a new file.
-  if (FileId == SM.getMainFileID())
+  if (FileId == SM.getMainFileID() || FileId == PP.getPredefinesFileID())
     WriteLineInfo(FileName, 1, FileType, EOL, "");
   else
     WriteLineInfo(FileName, 1, FileType, EOL, " 1");

+ 9 - 0
test/Frontend/rewrite-includes-cli-include.c

@@ -0,0 +1,9 @@
+// RUN: not %clang_cc1 -verify -E -frewrite-includes -include %S/Inputs/rewrite-includes2.h %s -o - | FileCheck -strict-whitespace %s
+main_file_line
+// CHECK: {{^}}# 1 "<built-in>"{{$}}
+// CHECK-NEXT: {{^}}# 1 "{{.*[/\\]Inputs(/|\\\\)}}rewrite-includes2.h" 1{{$}}
+// CHECK-NEXT: {{^}}included_line2{{$}}
+// CHECK-NEXT: {{^}}# 1 "<built-in>" 2{{$}}
+// CHECK-NEXT: {{^}}# 1 "{{.*}}rewrite-includes-cli-include.c"{{$}}
+// CHECK-NEXT: FileCheck
+// CHECK-NEXT: {{^}}main_file_line{{$}}