Skip to content

Commit

Permalink
Make -frewrite-includes handle -include correctly
Browse files Browse the repository at this point in the history
The `-include "file"` option implicitly adds a leading #include
to the main source; however, there's no explicit #include, which
left -frewrite-includes emitting an unmatched #endif at the end
of the included text.

This corrects a bug in 4a16b51.
  • Loading branch information
pogo59 committed Oct 24, 2023
1 parent 4c600bd commit 513b950
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 5 additions & 2 deletions clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,11 @@ void InclusionRewriter::Process(FileID FileId,
if (Mod)
OS << "#pragma clang module end /*"
<< Mod->getFullModuleName(true) << "*/\n";
OS << "#endif /* " << getIncludedFileName(Inc)
<< " expanded by -frewrite-includes */" << LocalEOL;
// There's no #include, therefore no #if, for -include files.
if (FromFile != PredefinesBuffer) {
OS << "#endif /* " << getIncludedFileName(Inc)
<< " expanded by -frewrite-includes */" << LocalEOL;
}

// Add line marker to indicate we're returning from an included
// file.
Expand Down
1 change: 0 additions & 1 deletion clang/test/Frontend/rewrite-includes-cli-include.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ main_file_line
// CHECK: {{^}}# 1 "<built-in>"{{$}}
// CHECK-NEXT: {{^}}# 1 "{{.*[/\\]Inputs(/|\\\\)}}rewrite-includes2.h" 1{{$}}
// CHECK-NEXT: {{^}}int included_line2;{{$}}
// CHECK-NEXT: {{^}}#endif /* rewrite-includes2.h expanded by -frewrite-includes */{{$}}
// CHECK-NEXT: {{^}}# 1 "<built-in>" 2{{$}}
// CHECK-NEXT: {{^}}# 1 "{{.*}}rewrite-includes-cli-include.c"{{$}}
// CHECK-NEXT: FileCheck
Expand Down

0 comments on commit 513b950

Please sign in to comment.