[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-08-10 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In https://reviews.llvm.org/D46652#1174220, @mikerice wrote:

> In https://reviews.llvm.org/D46652#1164010, @thakis wrote:
>
> > Also, were you planning on also adding support for the (filename-less 
> > version of) hdrstop pragma? After this change, that should probably be 
> > fairly straightforward.
>
>
> Thanks for taking a look.  I'll be going through our PCH tests at some point 
> soon and will likely add support for this and any other interesting issues 
> that remain.


Cool :-) I gave hrdstop a try (wip at https://reviews.llvm.org/D49496) but kind 
of got stuck and haven't had time to become unstuck. If you get to it first, 
maybe the wip patch is useful (or not).

It looks like your change did break using /P together with /Yu: 
https://bugs.llvm.org/show_bug.cgi?id=38508


Repository:
  rC Clang

https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-24 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

In https://reviews.llvm.org/D46652#1164010, @thakis wrote:

> Also, were you planning on also adding support for the (filename-less version 
> of) hdrstop pragma? After this change, that should probably be fairly 
> straightforward.


Thanks for taking a look.  I'll be going through our PCH tests at some point 
soon and will likely add support for this and any other interesting issues that 
remain.

In https://reviews.llvm.org/D46652#1166317, @thakis wrote:

> In https://reviews.llvm.org/D46652#1164016, @thakis wrote:
>
> > And finally (sorry about all the mails), this should probably be mentioned 
> > in the release notes (docs/ReleaseNotes.rst in the clang repo) since it's a 
> > notable new feature :-)
>
>
> I added this to releasenotes in r337381.


Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-18 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

In https://reviews.llvm.org/D46652#1164016, @thakis wrote:

> And finally (sorry about all the mails), this should probably be mentioned in 
> the release notes (docs/ReleaseNotes.rst in the clang repo) since it's a 
> notable new feature :-)


I added this to releasenotes in r337381.


Repository:
  rC Clang

https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-16 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

And finally (sorry about all the mails), this should probably be mentioned in 
the release notes (docs/ReleaseNotes.rst in the clang repo) since it's a 
notable new feature :-)


Repository:
  rC Clang

https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-16 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Also, were you planning on also adding support for the (filename-less version 
of) hdrstop pragma? After this change, that should probably be fairly 
straightforward.


Repository:
  rC Clang

https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-16 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Sorry about missing this. Looks great, thanks for doing this. This was a pretty 
big omission, glad to see it's done now :-)

I always imagined we might reuse the precompiled preamble stuff 
(Lexer::ComputePreamble() etc), but it's pretty clear as-is.


Repository:
  rC Clang

https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-05 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL336379: [clang-cl, PCH] Implement support for MS-style PCH 
through headers (authored by erichkeane, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46652?vs=153067&id=154264#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46652

Files:
  cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/include/clang/Frontend/FrontendOptions.h
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/include/clang/Lex/PreprocessorOptions.h
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInstance.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Lex/PPDirectives.cpp
  cfe/trunk/lib/Lex/PPLexerChange.cpp
  cfe/trunk/lib/Lex/Preprocessor.cpp
  cfe/trunk/lib/Parse/ParseAST.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/test/Driver/cl-pch-search.cpp
  cfe/trunk/test/Driver/cl-pch.cpp

Index: cfe/trunk/include/clang/Driver/CC1Options.td
===
--- cfe/trunk/include/clang/Driver/CC1Options.td
+++ cfe/trunk/include/clang/Driver/CC1Options.td
@@ -607,10 +607,9 @@
 
 def foverride_record_layout_EQ : Joined<["-"], "foverride-record-layout=">,
   HelpText<"Override record layouts with those in the given file">;
-def find_pch_source_EQ : Joined<["-"], "find-pch-source=">,
-  HelpText<"When building a pch, try to find the input file in include "
-   "directories, as if it had been included by the argument passed "
-   "to this flag.">;
+def pch_through_header_EQ : Joined<["-"], "pch-through-header=">,
+  HelpText<"Stop PCH generation after including this file.  When using a PCH, "
+   "skip tokens until after this file is included.">;
 def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">,
   HelpText<"Disable inclusion of timestamp in precompiled headers">;
 def building_pch_with_obj : Flag<["-"], "building-pch-with-obj">,
Index: cfe/trunk/include/clang/Lex/PreprocessorOptions.h
===
--- cfe/trunk/include/clang/Lex/PreprocessorOptions.h
+++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h
@@ -54,6 +54,13 @@
   /// definitions and expansions.
   bool DetailedRecord = false;
 
+  /// If non-empty, the filename used in an #include directive in the primary
+  /// source file (or command-line preinclude) that is used to implement
+  /// MSVC-style precompiled headers. When creating a PCH, after the #include
+  /// of this header, the PCH generation stops. When using a PCH, tokens are
+  /// skipped until after an #include of this header is seen.
+  std::string PCHThroughHeader;
+
   /// The implicit PCH included at the start of the translation unit, or empty.
   std::string ImplicitPCHInclude;
 
Index: cfe/trunk/include/clang/Lex/Preprocessor.h
===
--- cfe/trunk/include/clang/Lex/Preprocessor.h
+++ cfe/trunk/include/clang/Lex/Preprocessor.h
@@ -720,6 +720,12 @@
   /// The file ID for the preprocessor predefines.
   FileID PredefinesFileID;
 
+  /// The file ID for the PCH through header.
+  FileID PCHThroughHeaderFileID;
+
+  /// Whether tokens are being skipped until the through header is seen.
+  bool SkippingUntilPCHThroughHeader = false;
+
   /// \{
   /// Cache of macro expanders to reduce malloc traffic.
   enum { TokenLexerCacheSize = 8 };
@@ -1140,6 +1146,22 @@
   /// all macro expansions, macro definitions, etc.
   void createPreprocessingRecord();
 
+  /// Returns true if the FileEntry is the PCH through header.
+  bool isPCHThroughHeader(const FileEntry *File);
+
+  /// True if creating a PCH with a through header.
+  bool creatingPCHWithThroughHeader();
+
+  /// True if using a PCH with a through header.
+  bool usingPCHWithThroughHeader();
+
+  /// Skip tokens until after the #include of the through header.
+  void SkipTokensUntilPCHThroughHeader();
+
+  /// Process directives while skipping until the through header is found.
+  void HandleSkippedThroughHeaderDirective(Token &Result,
+   SourceLocation HashLoc);
+
   /// Enter the specified FileID as the main source file,
   /// which implicitly adds the builtin defines etc.
   void EnterMainSourceFile();
@@ -2020,6 +2042,9 @@
 PredefinesFileID = FID;
   }
 
+  /// Set the FileID for the PCH through header.
+  void setPCHThroughHeaderFileID(FileID FID);
+
   /// Returns true if we are lexing from a file and not a
   /// pragma or a macro.
   static bool IsFileLexer(const Lexer* L, const PreprocessorLexer* P) {
Index: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
+++ cfe/trunk/include/

[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-05 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC336379: [clang-cl, PCH] Implement support for MS-style PCH 
through headers (authored by erichkeane, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46652?vs=153067&id=154265#toc

Repository:
  rC Clang

https://reviews.llvm.org/D46652

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/FrontendOptions.h
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInstance.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PPLexerChange.cpp
  lib/Lex/Preprocessor.cpp
  lib/Parse/ParseAST.cpp
  lib/Serialization/ASTReader.cpp
  test/Driver/cl-pch-search.cpp
  test/Driver/cl-pch.cpp

Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -607,10 +607,9 @@
 
 def foverride_record_layout_EQ : Joined<["-"], "foverride-record-layout=">,
   HelpText<"Override record layouts with those in the given file">;
-def find_pch_source_EQ : Joined<["-"], "find-pch-source=">,
-  HelpText<"When building a pch, try to find the input file in include "
-   "directories, as if it had been included by the argument passed "
-   "to this flag.">;
+def pch_through_header_EQ : Joined<["-"], "pch-through-header=">,
+  HelpText<"Stop PCH generation after including this file.  When using a PCH, "
+   "skip tokens until after this file is included.">;
 def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">,
   HelpText<"Disable inclusion of timestamp in precompiled headers">;
 def building_pch_with_obj : Flag<["-"], "building-pch-with-obj">,
Index: include/clang/Lex/PreprocessorOptions.h
===
--- include/clang/Lex/PreprocessorOptions.h
+++ include/clang/Lex/PreprocessorOptions.h
@@ -54,6 +54,13 @@
   /// definitions and expansions.
   bool DetailedRecord = false;
 
+  /// If non-empty, the filename used in an #include directive in the primary
+  /// source file (or command-line preinclude) that is used to implement
+  /// MSVC-style precompiled headers. When creating a PCH, after the #include
+  /// of this header, the PCH generation stops. When using a PCH, tokens are
+  /// skipped until after an #include of this header is seen.
+  std::string PCHThroughHeader;
+
   /// The implicit PCH included at the start of the translation unit, or empty.
   std::string ImplicitPCHInclude;
 
Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -720,6 +720,12 @@
   /// The file ID for the preprocessor predefines.
   FileID PredefinesFileID;
 
+  /// The file ID for the PCH through header.
+  FileID PCHThroughHeaderFileID;
+
+  /// Whether tokens are being skipped until the through header is seen.
+  bool SkippingUntilPCHThroughHeader = false;
+
   /// \{
   /// Cache of macro expanders to reduce malloc traffic.
   enum { TokenLexerCacheSize = 8 };
@@ -1140,6 +1146,22 @@
   /// all macro expansions, macro definitions, etc.
   void createPreprocessingRecord();
 
+  /// Returns true if the FileEntry is the PCH through header.
+  bool isPCHThroughHeader(const FileEntry *File);
+
+  /// True if creating a PCH with a through header.
+  bool creatingPCHWithThroughHeader();
+
+  /// True if using a PCH with a through header.
+  bool usingPCHWithThroughHeader();
+
+  /// Skip tokens until after the #include of the through header.
+  void SkipTokensUntilPCHThroughHeader();
+
+  /// Process directives while skipping until the through header is found.
+  void HandleSkippedThroughHeaderDirective(Token &Result,
+   SourceLocation HashLoc);
+
   /// Enter the specified FileID as the main source file,
   /// which implicitly adds the builtin defines etc.
   void EnterMainSourceFile();
@@ -2020,6 +2042,9 @@
 PredefinesFileID = FID;
   }
 
+  /// Set the FileID for the PCH through header.
+  void setPCHThroughHeaderFileID(FileID FID);
+
   /// Returns true if we are lexing from a file and not a
   /// pragma or a macro.
   static bool IsFileLexer(const Lexer* L, const PreprocessorLexer* P) {
Index: include/clang/Basic/DiagnosticLexKinds.td
===
--- include/clang/Basic/DiagnosticLexKinds.td
+++ include/clang/Basic/DiagnosticLexKinds.td
@@ -404,6 +404,14 @@
 def err_pp_directive_required : Error<
   "%0 must be used within a preprocessing directive">;
 def err_pp_file_not_found : Error<"'%0' file not found">, DefaultFatal;
+def err_pp_through_header_not_found : Error<
+  "'%0' required for precompiled header not found

[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-05 Thread Mike Rice via Phabricator via cfe-commits
mikerice added inline comments.



Comment at: include/clang/Driver/CC1Options.td:604
+  HelpText<"When creating a pch stop at this file.  When using a pch start "
+   "after this file.">;
 def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">,

hans wrote:
> mikerice wrote:
> > hans wrote:
> > > The "through header" terminology was new to me, and I didn't see it when 
> > > browsing the MSDN articles about precompiled headers. The HelpText here 
> > > probably isn't the right place, but it would be good if the term could be 
> > > documented somewhere to make it clearer exactly what the behaviour is. 
> > > It's not really obvious to me what "stop at this file" and "start after 
> > > this file"  means. I can guess, but it would be nice if it were more 
> > > explicit :-)
> > You definitely have to look hard at the MSDN docs to find mention of 
> > through headers.  If you look at the documentation for /Yc and /Yu you can 
> > see some vague references.  I think it may have been more prominent many 
> > years ago. 
> > 
> > The MSDN page says "For /Yc, filename specifies the point at which 
> > precompilation stops; the compiler precompiles all code though(sic) 
> > filename..." https://msdn.microsoft.com/en-us/library/z0atkd6c.aspx
> > 
> > I'll look for a place to document this better in a comment at least.
> > 
> > 
> Thanks for the pointer. Yeah, a clear explanation in a comment somewhere 
> would be really helpful. Another idea might be to have a little "precompiled 
> headers" section in the clang-cl section of docs/UsersManual.rst. Maybe we 
> could do a better job than MS at explaining it precisely? :-)
Thanks for the review.  In the last patch I updated the comment in 
PreprocessorOptions.h  to better explain what a through header is.  I like the 
idea of explaining this in UsersManual.rst.  I'll work on that in the next few 
weeks. 


https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-06-29 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

This looks good to me.




Comment at: include/clang/Driver/CC1Options.td:604
+  HelpText<"When creating a pch stop at this file.  When using a pch start "
+   "after this file.">;
 def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">,

mikerice wrote:
> hans wrote:
> > The "through header" terminology was new to me, and I didn't see it when 
> > browsing the MSDN articles about precompiled headers. The HelpText here 
> > probably isn't the right place, but it would be good if the term could be 
> > documented somewhere to make it clearer exactly what the behaviour is. It's 
> > not really obvious to me what "stop at this file" and "start after this 
> > file"  means. I can guess, but it would be nice if it were more explicit :-)
> You definitely have to look hard at the MSDN docs to find mention of through 
> headers.  If you look at the documentation for /Yc and /Yu you can see some 
> vague references.  I think it may have been more prominent many years ago. 
> 
> The MSDN page says "For /Yc, filename specifies the point at which 
> precompilation stops; the compiler precompiles all code though(sic) 
> filename..." https://msdn.microsoft.com/en-us/library/z0atkd6c.aspx
> 
> I'll look for a place to document this better in a comment at least.
> 
> 
Thanks for the pointer. Yeah, a clear explanation in a comment somewhere would 
be really helpful. Another idea might be to have a little "precompiled headers" 
section in the clang-cl section of docs/UsersManual.rst. Maybe we could do a 
better job than MS at explaining it precisely? :-)


https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-06-27 Thread Mike Rice via Phabricator via cfe-commits
mikerice added inline comments.



Comment at: include/clang/Driver/CC1Options.td:604
+  HelpText<"When creating a pch stop at this file.  When using a pch start "
+   "after this file.">;
 def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">,

hans wrote:
> The "through header" terminology was new to me, and I didn't see it when 
> browsing the MSDN articles about precompiled headers. The HelpText here 
> probably isn't the right place, but it would be good if the term could be 
> documented somewhere to make it clearer exactly what the behaviour is. It's 
> not really obvious to me what "stop at this file" and "start after this file" 
>  means. I can guess, but it would be nice if it were more explicit :-)
You definitely have to look hard at the MSDN docs to find mention of through 
headers.  If you look at the documentation for /Yc and /Yu you can see some 
vague references.  I think it may have been more prominent many years ago. 

The MSDN page says "For /Yc, filename specifies the point at which 
precompilation stops; the compiler precompiles all code though(sic) 
filename..." https://msdn.microsoft.com/en-us/library/z0atkd6c.aspx

I'll look for a place to document this better in a comment at least.





Comment at: lib/Lex/PPDirectives.cpp:1887
+  SkippingUntilPCHThroughHeader = false;
+return;
+  }

hans wrote:
> Returning here seemed surprising to me. Isn't just setting the flag and then 
> carrying on as usual what we want?
When skipping we always return since we don't want to include any headers 
encountered because they are in the PCH.  When the 'through header' is seen we 
also return because it too is in the PCH.  In that case we also set the flag to 
stop the skipping.  

So with /Yu"hdr2.h":

#include "hdr1.h"  <- in PCH
#include "hdr2.h"  <-  in PCH
#include "hdr3.h"  <- next include processed normally.

That's because /Yc"hdr2.h" contains all the headers "through" hdr2.h (i.e. 
hdr1.h and hdr2.h).



https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-06-27 Thread Mike Rice via Phabricator via cfe-commits
mikerice updated this revision to Diff 153067.
mikerice marked 8 inline comments as done.
mikerice added a comment.

Thanks for the review.  Updated based on comments.


https://reviews.llvm.org/D46652

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/FrontendOptions.h
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInstance.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PPLexerChange.cpp
  lib/Lex/Preprocessor.cpp
  lib/Parse/ParseAST.cpp
  lib/Serialization/ASTReader.cpp
  test/Driver/cl-pch-search.cpp
  test/Driver/cl-pch.cpp
  test/PCH/Inputs/pch-through-use0.cpp
  test/PCH/Inputs/pch-through-use1.cpp
  test/PCH/Inputs/pch-through-use2.cpp
  test/PCH/Inputs/pch-through-use3a.cpp
  test/PCH/Inputs/pch-through-use3b.cpp
  test/PCH/Inputs/pch-through1.h
  test/PCH/Inputs/pch-through2.h
  test/PCH/Inputs/pch-through3.h
  test/PCH/Inputs/pch-through4.h
  test/PCH/pch-through1.cpp
  test/PCH/pch-through2.cpp
  test/PCH/pch-through3a.cpp
  test/PCH/pch-through3b.cpp

Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -704,6 +704,17 @@
   // Compute the #include and #include_macros lines we need.
   for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) {
 StringRef File = ExistingPPOpts.Includes[I];
+
+if (!ExistingPPOpts.ImplicitPCHInclude.empty() &&
+!ExistingPPOpts.PCHThroughHeader.empty()) {
+  // In case the through header is an include, we must add all the includes
+  // to the predefines so the start point can be determined.
+  SuggestedPredefines += "#include \"";
+  SuggestedPredefines += File;
+  SuggestedPredefines += "\"\n";
+  continue;
+}
+
 if (File == ExistingPPOpts.ImplicitPCHInclude)
   continue;
 
Index: lib/Parse/ParseAST.cpp
===
--- lib/Parse/ParseAST.cpp
+++ lib/Parse/ParseAST.cpp
@@ -141,6 +141,12 @@
 CleanupParser(ParseOP.get());
 
   S.getPreprocessor().EnterMainSourceFile();
+  if (!S.getPreprocessor().getCurrentLexer()) {
+// If a PCH through header is specified that does not have an include in
+// the source, there won't be any tokens or a Lexer.
+return;
+  }
+
   P.Initialize();
 
   Parser::DeclGroupPtrTy ADecl;
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -2991,22 +2991,6 @@
 Args.eraseArg(options::OPT__SLASH_Yu);
 YcArg = YuArg = nullptr;
   }
-  if (YcArg || YuArg) {
-StringRef Val = YcArg ? YcArg->getValue() : YuArg->getValue();
-bool FoundMatchingInclude = false;
-for (const Arg *Inc : Args.filtered(options::OPT_include)) {
-  // FIXME: Do case-insensitive matching and consider / and \ as equal.
-  if (Inc->getValue() == Val)
-FoundMatchingInclude = true;
-}
-if (!FoundMatchingInclude) {
-  Diag(clang::diag::warn_drv_ycyu_no_fi_arg_clang_cl)
-  << (YcArg ? YcArg : YuArg)->getSpelling();
-  Args.eraseArg(options::OPT__SLASH_Yc);
-  Args.eraseArg(options::OPT__SLASH_Yu);
-  YcArg = YuArg = nullptr;
-}
-  }
   if (YcArg && Inputs.size() > 1) {
 Diag(clang::diag::warn_drv_yc_multiple_inputs_clang_cl);
 Args.eraseArg(options::OPT__SLASH_Yc);
@@ -3076,11 +3060,9 @@
 const types::ID HeaderType = lookupHeaderTypeForSourceType(InputType);
 llvm::SmallVector PCHPL;
 types::getCompilationPhases(HeaderType, PCHPL);
-Arg *PchInputArg = MakeInputArg(Args, *Opts, YcArg->getValue());
-
 // Build the pipeline for the pch file.
 Action *ClangClPch =
-C.MakeAction(*PchInputArg, HeaderType);
+C.MakeAction(*InputArg, HeaderType);
 for (phases::ID Phase : PCHPL)
   ClangClPch = ConstructPhaseAction(C, Args, Phase, ClangClPch);
 assert(ClangClPch);
@@ -4269,6 +4251,9 @@
 // extension of .pch is assumed. "
 if (!llvm::sys::path::has_extension(Output))
   Output += ".pch";
+  } else if (Arg *YcArg = C.getArgs().getLastArg(options::OPT__SLASH_Yc)) {
+Output = YcArg->getValue();
+llvm::sys::path::replace_extension(Output, ".pch");
   } else {
 Output = BaseName;
 llvm::sys::path::replace_extension(Output, ".pch");
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -1060,77 +1060,28 @@
   // wonky, but we include looking for .gch so we can support seamless
   // replacement into a build system already set up to be generating
   // .gch files.
-  int YcIndex = -1, YuIndex = -1;
-  {
-int AI

[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-06-26 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

This looks reasonable to me as far as I can tell. Thanks!

I think the expert on the driver side for this stuff is Nico, so hopefully he 
can take a look as well.




Comment at: include/clang/Basic/DiagnosticLexKinds.td:412
+  "%select{create|use}1 precompiled header">, DefaultFatal;
+def err_pp_macro_def_mismatch_with_pch : Warning<
+  "definition of macro %0 does not match definition in precompiled header">,

Should probably just have a warn_ prefix.



Comment at: include/clang/Driver/CC1Options.td:604
+  HelpText<"When creating a pch stop at this file.  When using a pch start "
+   "after this file.">;
 def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">,

The "through header" terminology was new to me, and I didn't see it when 
browsing the MSDN articles about precompiled headers. The HelpText here 
probably isn't the right place, but it would be good if the term could be 
documented somewhere to make it clearer exactly what the behaviour is. It's not 
really obvious to me what "stop at this file" and "start after this file"  
means. I can guess, but it would be nice if it were more explicit :-)



Comment at: include/clang/Lex/Preprocessor.h:2050
+PCHThroughHeaderFileID = FID;
+  }
+

I would probably define this out-of-line like the other methods you added, but 
no big deal.



Comment at: lib/Driver/ToolChains/Clang.cpp:1091
+  Args.MakeArgString(Twine("-pch-through-header=") + ThroughHeader));
 }
   }

In r335466, I added the -building-pch-with-obj flag. This is probably the right 
place to pass it when there's a /Yc flag.



Comment at: lib/Lex/PPDirectives.cpp:1887
+  SkippingUntilPCHThroughHeader = false;
+return;
+  }

Returning here seemed surprising to me. Isn't just setting the flag and then 
carrying on as usual what we want?



Comment at: lib/Lex/PPLexerChange.cpp:344
   const bool LeavingSubmodule = CurLexer && CurLexerSubmodule;
+  bool LeavingPCHThroughHeader = false;
   if ((LeavingSubmodule || IncludeMacroStack.empty()) &&

Maybe move this down to where it's first used?



Comment at: lib/Lex/Preprocessor.cpp:583
+
+/// Return true if the FileEntry is the PCH through header.
+bool Preprocessor::isPCHThroughHeader(const FileEntry *FE) {

I know some functions already do this, but I don't think repeating the comment 
from the .h file here is necessary, it's just another thing to keep in sync. 
Same for the other small methods below.



Comment at: lib/Lex/Preprocessor.cpp:607
+void Preprocessor::SkipTokensUntilPCHThroughHeader()
+{
+  bool ReachedMainFileEOF = false;

nit: curly on the previous line



Comment at: test/PCH/pch-through2.cpp:3
+// RUN: %clang_cc1 -I %S -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -o %t.s2t2 %s
+

What's s2t2 for? From what I see, there's only two pch files used in this test, 
so I would have gone with %t.1 and %t.2


https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-06-20 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In https://reviews.llvm.org/D46652#1138375, @rnk wrote:

> @hans, think you'll have time to look at this with your recent dllexport PCH 
> experimentation?


Yes, I mean to look at it, marked it unread in my inbox and everything.


https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-06-20 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

@hans, think you'll have time to look at this with your recent dllexport PCH 
experimentation?


https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-06-18 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

Ping.  This can significantly improve compile time for projects that use the 
common /Yc /Yu PCH mechanism.


https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-05-23 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

Ping. Still looking for a reviewer, mostly Lex and clang-cl driver changes.


https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-05-17 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.



>> Can you test what happens when you do clang-cl.exe /Yc stdafx.h /Tp 
>> stdafx.h, i.e. compile the header
>  > directly as C++ code and generate .pch from it? The normal MSVC modus 
> operandi is to have stdafx.h
>  > included in all source files (with /Yu) and stdafx.cpp to generate it 
> (with /Yc). That stdafx.cpp file serves
>  > no purpose, so I've played this trick to generate PCH from the header 
> directly. If it works, it might also
>  > be useful for your tests.
> 
> It isn't always the case that the .cpp file serves no purpose. It's true that 
> the MS project generators give you this setup but we've seen many projects 
> over the years that use a regular source file with code in it to generate the 
> PCH. The > object file generated during PCH create can have real code and the 
> compiler can take advantage of that fact by compiling less code in the 
> compilation units that use the PCH [...]

Cool, it's never occurred to me that the source file has any other purpose than 
including the pch header.

> I am not sure about your command: clang-cl.exe /Yc stdafx.h /Tp stdafx.h. The 
> space makes this a compile with just
>  /Yc (no through header). This patch doesn't address /Yc without the through 
> header. Something like clang-cl /Yc 
> /Tpstdafx.h would probably work if/when that is implemented.

I no longer have access to an MSVC environment, so I can't spell out the exact 
command, but I was trying to phrase a command that generates a PCH from the 
through-header *without a distinct source file*. It's proved to be a useful 
trick. I didn't mean to omit the through header, let's try again:

  cl.exe /Ycstdafx.h /TP stdafx.h

or if that doesn't work, a /FI switch may be required, I can't remember for 
sure what we did:

  cl.exe /Ycstdafx.h /TP /FI stdafx.h stdafx.h

>> I think the current skip-warning is over-specific -- what if I put an inline 
>> function before my PCH include?
>  >  A global variable? A #pragma? Or am I misunderstanding what skipping 
> does? It seems to me that any
>  > non-comment tokens before the PCH #include should raise a warning.
> 
> Not any tokens. The through header "feature" compiles all the code in the 
> file up to the through header.
>  So normally you are used to seeing just comments and #include . 
> That's one usage but your
>  PCH can be created from a source like this [...]

Thanks for the example, I must have misunderstood how MSVC PCHs work. With that 
background, the warning seems fine.

>> I find the "through header" terminology is a little hard to interpret, but I 
>> did find it on MSDN, so maybe it's well established.
> 
> Sorry about the terminology. I've been responsible for emulating this PCH 
> mechanism for many years so I may be one
>  of the few that understands it. I did try to keep that terminology out of 
> the diagnostics but I don't really have a better
>  name for through header.

:) Sounds like it's well-established!


https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-05-16 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

In https://reviews.llvm.org/D46652#1101952, @kimgr wrote:

>




> - Can you test what happens when you do `clang-cl.exe /Yc stdafx.h /Tp 
> stdafx.h`, i.e. compile the header directly as C++ code and generate .pch 
> from it?  The normal MSVC modus operandi is to have stdafx.h included in all 
> source files (with /Yu) and stdafx.cpp to generate it (with /Yc). That 
> stdafx.cpp file serves no purpose, so I've played this trick to generate PCH 
> from the header directly. If it works, it might also be useful for your tests.

It isn't always the case that the .cpp file serves no purpose.  It's true that 
the MS project generators give you this setup but we've seen many projects over 
the years that use a regular source file with code in it to generate the PCH.  
The object file generated during PCH create can have real code and the compiler 
can take advantage of that fact by compiling less code in the compilation units 
that use the PCH (for example not instantiating some COMDAT data/functions that 
are know to be in the create object).  This can speed up compilations 
significantly in some cases.

I am not sure about your command:  `clang-cl.exe /Yc stdafx.h /Tp stdafx.h`.  
The space makes this a compile with just /Yc (no through header).  This patch 
doesn't address /Yc without the through header.  Something like clang-cl /Yc 
/Tpstdafx.h would probably work if/when that is implemented.

> - I think the current skip-warning is over-specific -- what if I put an 
> inline function before my PCH include? A global variable? A #pragma? Or am I 
> misunderstanding what skipping does? It seems to me that any non-comment 
> tokens before the PCH #include should raise a warning.

Not any tokens.  The through header "feature" compiles all the code in the file 
up to the through header.  So normally you are used to seeing just comments and 
#include .  That's one usage but your PCH can be created from a 
source like this:

  #include 
  #ifdef FOO
  #define FOO1
  #endif
  #include 
  #include 

If the files using the PCH also have exactly this 'pch prefix' there is no 
problem and certainly no warning is expected.  Some compilers also check that 
this 'prefix' matches and won't use a PCH if it doesn't match. The MS compiler 
does not do this but they do give a warning if a #define is seen that doesn't 
match the definition in the PCH (that may be new I hadn't noticed it before you 
mentioned it).  It's a sign that the user is likely doing something wrong so a 
warning is probably warranted.   We can do some simple checks here but I 
suppose the user is most interested in compilation speed when using a PCH.

> - I find the "through header" terminology is a little hard to interpret, but 
> I did find it on MSDN, so maybe it's well established.

Sorry about the terminology.  I've been responsible for emulating this PCH 
mechanism for many years so I may be one of the few that understands it.  I did 
try to keep that terminology out of the diagnostics but I don't really have a 
better name for through header.

Thanks for taking a look at this.


https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-05-16 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

I've done some terrible things with MSVC PCHs over the years, so I'll pile on 
some more questions:

- Can you test what happens when you do `clang-cl.exe /Yc stdafx.h /Tp 
stdafx.h`, i.e. compile the header directly as C++ code and generate .pch from 
it?  The normal MSVC modus operandi is to have stdafx.h included in all source 
files (with /Yu) and stdafx.cpp to generate it (with /Yc). That stdafx.cpp file 
serves no purpose, so I've played this trick to generate PCH from the header 
directly. If it works, it might also be useful for your tests.
- I think the current skip-warning is over-specific -- what if I put an inline 
function before my PCH include? A global variable? A #pragma? Or am I 
misunderstanding what skipping does? It seems to me that any non-comment tokens 
before the PCH #include should raise a warning.
- I find the "through header" terminology is a little hard to interpret, but I 
did find it on MSDN, so maybe it's well established.

I'll try to look more at this patch in context later.


https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-05-16 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

@hans @thakis, do you remember how these flags are supposed to work? I've 
forgotten anything I ever knew about them...


https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-05-13 Thread Mike Rice via Phabricator via cfe-commits
mikerice updated this revision to Diff 146513.
mikerice added a comment.

Added warning when macro is defined when skipping.  Also fixed skipping so 
directives are completely ignored expect for #include and #define.


https://reviews.llvm.org/D46652

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/FrontendOptions.h
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInstance.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PPLexerChange.cpp
  lib/Lex/Preprocessor.cpp
  lib/Parse/ParseAST.cpp
  lib/Serialization/ASTReader.cpp
  test/Driver/cl-pch-search.cpp
  test/Driver/cl-pch.cpp
  test/PCH/Inputs/pch-through-use0.cpp
  test/PCH/Inputs/pch-through-use1.cpp
  test/PCH/Inputs/pch-through-use2.cpp
  test/PCH/Inputs/pch-through-use3a.cpp
  test/PCH/Inputs/pch-through-use3b.cpp
  test/PCH/Inputs/pch-through1.h
  test/PCH/Inputs/pch-through2.h
  test/PCH/Inputs/pch-through3.h
  test/PCH/Inputs/pch-through4.h
  test/PCH/pch-through1.cpp
  test/PCH/pch-through2.cpp
  test/PCH/pch-through3a.cpp
  test/PCH/pch-through3b.cpp

Index: test/PCH/pch-through3b.cpp
===
--- /dev/null
+++ test/PCH/pch-through3b.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -I %S -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through1.h -o %t.s3bt1 %s
+
+// RUN: %clang_cc1 -I %S -include-pch %t.s3bt1 \
+// RUN:   -pch-through-header=Inputs/pch-through1.h \
+// RUN:   %S/Inputs/pch-through-use3b.cpp 2>&1 | FileCheck %s
+
+//CHECK: warning: definition of macro 'AFOO' does not match definition in
+//CHECK-SAME: precompiled header
+//CHECK: warning: definition of macro 'BFOO' does not match definition in
+//CHECK-SAME: precompiled header
+
+#define AFOO 0
+#include "Inputs/pch-through1.h"
Index: test/PCH/pch-through3a.cpp
===
--- /dev/null
+++ test/PCH/pch-through3a.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -verify -I %S -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through1.h -o %t.s3at1 %s
+
+// RUN: %clang_cc1 -I %S -include-pch %t.s3at1 \
+// RUN:   -pch-through-header=Inputs/pch-through1.h \
+// RUN:   %S/Inputs/pch-through-use3a.cpp
+//expected-no-diagnostics
+
+#define AFOO 0
+#include "Inputs/pch-through1.h"
Index: test/PCH/pch-through2.cpp
===
--- /dev/null
+++ test/PCH/pch-through2.cpp
@@ -0,0 +1,28 @@
+// Create
+// RUN: %clang_cc1 -I %S -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -o %t.s2t2 %s
+
+// Use
+// RUN: %clang_cc1 -I %S -include-pch %t.s2t2 \
+// RUN:   -pch-through-header=Inputs/pch-through2.h %s
+
+// No #include of through header during pch use
+// RUN: not %clang_cc1 -I %S -include-pch %t.s2t2 \
+// RUN:   -pch-through-header=Inputs/pch-through2.h \
+// RUN:   %S/Inputs/pch-through-use1.cpp 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST2A %s
+// CHECK-TEST2A: fatal error:{{.*}} #include of
+// CHECK-TEST2A-SAME: 'Inputs/pch-through2.h' not seen while attempting to
+// CHECK-TEST2A-SAME: use precompiled header
+
+// check that pch only contains code before the through header.
+// RUN: %clang_cc1 -I %S -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through1.h -o %t.s2t1 %s
+// RUN: not %clang_cc1 -I %S -include-pch %t.s2t1 \
+// RUN:   -pch-through-header=Inputs/pch-through1.h \
+// RUN:   %S/Inputs/pch-through-use1.cpp 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST3 %s
+// CHECK-TEST3: error: use of undeclared identifier 'through2'
+
+#include "Inputs/pch-through1.h"
+#include "Inputs/pch-through2.h"
Index: test/PCH/pch-through1.cpp
===
--- /dev/null
+++ test/PCH/pch-through1.cpp
@@ -0,0 +1,34 @@
+// Through header not found (anywhere)
+// RUN: not %clang_cc1 -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-does-not-exist.h -o %t %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST0A %s
+// CHECK-TEST0A: fatal error:{{.*}} 'Inputs/pch-does-not-exist.h'
+// CHECK-TEST0A-SAME: required for precompiled header not found
+
+// Through header not found in search path
+// RUN: not %clang_cc1 -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -o %t \
+// RUN:   %S/Inputs/pch-through-use0.cpp 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST0B %s
+// CHECK-TEST0B: fatal error:{{.*}}'Inputs/pch-through2.h'
+// CHECK-TEST0B-SAME: required for precompiled header not found
+
+// No #include of through header during pch create
+// RUN: not %clang_cc1 -I %S -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -o %t %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST1A %s
+// CHECK-TEST1A: fatal error:{{.*}} #include of
+// CHECK-TEST1A-SAME: 'Inputs/pch-through2.h' not seen while attemptin

[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-05-13 Thread Mike Rice via Phabricator via cfe-commits
mikerice added a comment.

Thanks for taking a look at the patch.  I added a warning as suggested. I also 
fixed skipping so it ignores all directives except #include and now #define.


Repository:
  rC Clang

https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-05-11 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr added a comment.

> When using a PCH, tokens are skipped until after the through header is seen.

I know this is what MSVC does (though in their case I think it's an artifact of 
their implementation), but I remember this being a source of mysterious bugs:

  #define MY_SYMBOL 1
  #include "stdafx.h"  // include pch

The `#define` would silently disappear, and the symbol would never be defined. 
I wonder if it would be worth adding a warning for this in 
`SkipTokensUntilPCHThroughHeader`?


Repository:
  rC Clang

https://reviews.llvm.org/D46652



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-05-09 Thread Mike Rice via Phabricator via cfe-commits
mikerice created this revision.
mikerice added reviewers: rnk, thakis, erichkeane, cfe-commits.

Implement support for MS-style PCH through headers.

This enables support for /Yc and /Yu where the through header is either
on the command line or included in the source.  It replaces the current
support the requires the header also be specified with /FI.

This change adds a -cc1 option -pch-through-header that is used to either
start or stop compilation during PCH create or use.

When creating a PCH, the compilation ends after compilation of the through
header.

When using a PCH, tokens are skipped until after the through header is seen.


Repository:
  rC Clang

https://reviews.llvm.org/D46652

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/FrontendOptions.h
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInstance.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PPLexerChange.cpp
  lib/Lex/Preprocessor.cpp
  lib/Parse/ParseAST.cpp
  lib/Serialization/ASTReader.cpp
  test/Driver/cl-pch-search.cpp
  test/Driver/cl-pch.cpp
  test/PCH/Inputs/pch-through-use0.cpp
  test/PCH/Inputs/pch-through-use1.cpp
  test/PCH/Inputs/pch-through-use2.cpp
  test/PCH/Inputs/pch-through1.h
  test/PCH/Inputs/pch-through2.h
  test/PCH/Inputs/pch-through3.h
  test/PCH/Inputs/pch-through4.h
  test/PCH/pch-through.cpp

Index: test/PCH/pch-through.cpp
===
--- /dev/null
+++ test/PCH/pch-through.cpp
@@ -0,0 +1,72 @@
+// Through header not found (anywhere)
+// RUN: not %clang_cc1 -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-does-not-exist.h -o %t %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST0A %s
+// CHECK-TEST0A: fatal error:{{.*}} 'Inputs/pch-does-not-exist.h'
+// CHECK-TEST0A-SAME: required for precompiled header not found
+
+// Through header not found in search path
+// RUN: not %clang_cc1 -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -o %t \
+// RUN:   %S/Inputs/pch-through-use0.cpp 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST0B %s
+// CHECK-TEST0B: fatal error:{{.*}}'Inputs/pch-through2.h'
+// CHECK-TEST0B-SAME: required for precompiled header not found
+
+// No #include of through header during pch create
+// RUN: not %clang_cc1 -DSOURCE1 -I %S -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -o %t %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST1A %s
+// CHECK-TEST1A: fatal error:{{.*}} #include of
+// CHECK-TEST1A-SAME: 'Inputs/pch-through2.h' not seen while attempting to
+// CHECK-TEST1A-SAME: create precompiled header
+
+#ifdef SOURCE1
+#endif
+
+// Create
+// RUN: %clang_cc1 -DSOURCE2 -I %S -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -o %t.s2t2 %s
+
+// Use
+// RUN: %clang_cc1 -DSOURCE2 -I %S -include-pch %t.s2t2 \
+// RUN:   -pch-through-header=Inputs/pch-through2.h %s
+
+#ifdef SOURCE2
+#include "Inputs/pch-through1.h"
+#include "Inputs/pch-through2.h"
+#endif
+
+// No #include of through header during pch use
+// RUN: not %clang_cc1 -I %S -include-pch %t.s2t2 \
+// RUN:   -pch-through-header=Inputs/pch-through2.h \
+// RUN:   %S/Inputs/pch-through-use1.cpp 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST2A %s
+// CHECK-TEST2A: fatal error:{{.*}} #include of
+// CHECK-TEST2A-SAME: 'Inputs/pch-through2.h' not seen while attempting to
+// CHECK-TEST2A-SAME: use precompiled header
+
+// check that pch only contains code before the through header.
+// RUN: %clang_cc1 -DSOURCE2 -I %S -emit-pch \
+// RUN:   -pch-through-header=Inputs/pch-through1.h -o %t.s2t1 %s
+// RUN: not %clang_cc1 -I %S -include-pch %t.s2t1 \
+// RUN:   -pch-through-header=Inputs/pch-through1.h \
+// RUN:   %S/Inputs/pch-through-use1.cpp 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK-TEST3 %s
+// CHECK-TEST3: error: use of undeclared identifier 'through2'
+
+#ifdef SOURCE3
+#endif
+
+// checks for through headers that are also -includes
+// RUN: %clang_cc1 -DSOURCE3 -I %S -include Inputs/pch-through1.h \
+// RUN:   -pch-through-header=Inputs/pch-through1.h -emit-pch -o %t.s3t1 %s
+// RUN: %clang_cc1 -DSOURCE3 -I %S -include Inputs/pch-through1.h \
+// RUN:   -include Inputs/pch-through2.h -include Inputs/pch-through3.h \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -emit-pch -o %t.s3t2 %s
+// Use through header from -includes
+// RUN: %clang_cc1 -DSOURCE3 -I %S -include Inputs/pch-through1.h \
+// RUN:   -include Inputs/pch-through2.h -include Inputs/pch-through4.h \
+// RUN:   -pch-through-header=Inputs/pch-through2.h -include-pch %t.s3t2 \
+// RUN:   %S/Inputs/pch-through-use2.cpp -o %t.out
+
Index: test/PCH/Inputs/pch-through4.h
===
--- /dev/null
+++ test/PCH/Inputs/pch-through4.h
@@ -0,0 +1,2 @@
+#define THROUGH4
+in