]> granicus.if.org Git - clang/commitdiff
PR26771: don't forget the " 2" (returning from #included file) linemarker after inclu...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 29 Apr 2017 00:54:03 +0000 (00:54 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 29 Apr 2017 00:54:03 +0000 (00:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301727 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/Rewrite/InclusionRewriter.cpp
test/Frontend/Inputs/empty.h [new file with mode: 0644]
test/Frontend/rewrite-includes-line-markers.c

index 7ca1934093ab89fa0fd8c9108e6c132a93bea5f8..ee61f76d029d63446491e903acf55cbb7ceaed96 100644 (file)
@@ -52,7 +52,7 @@ class InclusionRewriter : public PPCallbacks {
 public:
   InclusionRewriter(Preprocessor &PP, raw_ostream &OS, bool ShowLineMarkers,
                     bool UseLineDirectives);
-  bool Process(FileID FileId, SrcMgr::CharacteristicKind FileType);
+  void Process(FileID FileId, SrcMgr::CharacteristicKind FileType);
   void setPredefinesBuffer(const llvm::MemoryBuffer *Buf) {
     PredefinesBuffer = Buf;
   }
@@ -400,9 +400,8 @@ bool InclusionRewriter::HandleHasInclude(
 
 /// Use a raw lexer to analyze \p FileId, incrementally copying parts of it
 /// and including content of included files recursively.
-bool InclusionRewriter::Process(FileID FileId,
-                                SrcMgr::CharacteristicKind FileType)
-{
+void InclusionRewriter::Process(FileID FileId,
+                                SrcMgr::CharacteristicKind FileType) {
   bool Invalid;
   const MemoryBuffer &FromFile = *SM.getBuffer(FileId, &Invalid);
   assert(!Invalid && "Attempting to process invalid inclusion");
@@ -419,7 +418,7 @@ bool InclusionRewriter::Process(FileID FileId,
     WriteLineInfo(FileName, 1, FileType, " 1");
 
   if (SM.getFileIDSize(FileId) == 0)
-    return false;
+    return;
 
   // The next byte to be copied from the source file, which may be non-zero if
   // the lexer handled a BOM.
@@ -453,14 +452,11 @@ bool InclusionRewriter::Process(FileID FileId,
             if (const Module *Mod = FindModuleAtLocation(Loc))
               WriteImplicitModuleImport(Mod);
             else if (const IncludedFile *Inc = FindIncludeAtLocation(Loc)) {
-              // include and recursively process the file
-              if (Process(Inc->Id, Inc->FileType)) {
-                // and set lineinfo back to this file, if the nested one was
-                // actually included
-                // `2' indicates returning to a file (after having included
-                // another file.
-                LineInfoExtra = " 2";
-              }
+              // Include and recursively process the file.
+              Process(Inc->Id, Inc->FileType);
+              // Add line marker to indicate we're returning from an included
+              // file.
+              LineInfoExtra = " 2";
             }
             // fix up lineinfo (since commented out directive changed line
             // numbers) for inclusions that were skipped due to header guards
@@ -569,7 +565,6 @@ bool InclusionRewriter::Process(FileID FileId,
   OutputContentUpTo(FromFile, NextToWrite,
                     SM.getFileOffset(SM.getLocForEndOfFile(FileId)), LocalEOL,
                     Line, /*EnsureNewline=*/true);
-  return true;
 }
 
 /// InclusionRewriterInInput - Implement -frewrite-includes mode.
diff --git a/test/Frontend/Inputs/empty.h b/test/Frontend/Inputs/empty.h
new file mode 100644 (file)
index 0000000..e69de29
index 14692a19e9bcd9893af5a187e2ad30bbd1f8f585..f5fb627fec16c1c043d4fca115cfaf96a77dcb92 100644 (file)
@@ -3,6 +3,8 @@
 #include "test.h"
 int f() { return x; }
 
+#include "empty.h"
+
 // GNU: {{^}}# 1 "{{.*}}rewrite-includes-line-markers.c"
 // GNU: {{^}}#include "test.h"
 // GNU: {{^}}# 1 "{{.*}}test.h"
@@ -11,6 +13,9 @@ int f() { return x; }
 // GNU: {{^}}int x;
 // GNU: {{^}}# 4 "{{.*}}rewrite-includes-line-markers.c" 2
 // GNU: {{^}}int f() { return x; }
+// GNU: {{^}}
+// GNU: {{^}}# 1 "{{.*}}empty.h" 1
+// GNU: {{^}}# 7 "{{.*}}rewrite-includes-line-markers.c" 2
 
 // LINE: {{^}}#line 1 "{{.*}}rewrite-includes-line-markers.c"
 // LINE: {{^}}#include "test.h"
@@ -20,3 +25,6 @@ int f() { return x; }
 // LINE: {{^}}int x;
 // LINE: {{^}}#line 4 "{{.*}}rewrite-includes-line-markers.c"
 // LINE: {{^}}int f() { return x; }
+// LINE: {{^}}
+// LINE: {{^}}#line 1 "{{.*}}empty.h"
+// LINE: {{^}}#line 7 "{{.*}}rewrite-includes-line-markers.c"