Index: test/Frontend/fpredictive-compilation.c
===================================================================
--- test/Frontend/fpredictive-compilation.c	(revision 0)
+++ test/Frontend/fpredictive-compilation.c	(revision 0)
@@ -0,0 +1,4 @@
+// RUN: echo 'itn a;' | %clang -fpredictive-compilation %s -o - 2>&1 | FileCheck -check-prefix=RUN1 %s
+// CHECK-RUN1: fpredictive-compilation.c:1:1: error: unknown type name 'itn'
+// RUN: echo 'itn a;' | %clang -fpredictive-compilation=0 %s -o - 2>&1 | FileCheck -check-prefix=RUN2 %s
+// CHECK-RUN2: fpredictive-compilation.c:1:1: error: unknown type name 'itn'
Index: include/clang/Frontend/FrontendOptions.h
===================================================================
--- include/clang/Frontend/FrontendOptions.h	(revision 139582)
+++ include/clang/Frontend/FrontendOptions.h	(working copy)
@@ -123,6 +123,11 @@
   /// should only be used for debugging and experimental features.
   std::vector<std::string> LLVMArgs;
 
+  /// If this is non-empty, |Inputs| is used to determine input language and
+  /// default |OutputFile| contents, but the actual compiler input is read from
+  /// stdin.
+  std::string PredictiveCompilation;
+
 public:
   FrontendOptions() {
     DisableFree = 0;
Index: include/clang/Frontend/DiagnosticOptions.h
===================================================================
--- include/clang/Frontend/DiagnosticOptions.h	(revision 139582)
+++ include/clang/Frontend/DiagnosticOptions.h	(working copy)
@@ -72,6 +72,10 @@
   /// prefixes removed.
   std::vector<std::string> Warnings;
 
+  /// If non-empty, diagnostics for the main file are reported for this filename
+  /// instead.
+  std::string FakeDiagMainFile;
+
 public:
   DiagnosticOptions() {
     IgnoreWarnings = 0;
Index: include/clang/Driver/CC1Options.td
===================================================================
--- include/clang/Driver/CC1Options.td	(revision 139582)
+++ include/clang/Driver/CC1Options.td	(working copy)
@@ -542,6 +542,8 @@
   HelpText<"Support POSIX threads in generated code">;
 def fpascal_strings : Flag<"-fpascal-strings">,
   HelpText<"Recognize and construct Pascal-style string literals">;
+def fpredictive_compilation : Separate<"-fpredictive-compilation">,
+  HelpText<"Read compiler input from stdin, but still require an input filename">;
 def fno_rtti : Flag<"-fno-rtti">,
   HelpText<"Disable generation of rtti information">;
 def fno_validate_pch : Flag<"-fno-validate-pch">,
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td	(revision 139582)
+++ include/clang/Driver/Options.td	(working copy)
@@ -436,6 +436,8 @@
 def fpic : Flag<"-fpic">, Group<f_Group>;
 def fpie : Flag<"-fpie">, Group<f_Group>, Flags<[NoArgumentUnused]>;
 def fno_pie : Flag<"-fno-pie">, Group<f_Group>, Flags<[NoArgumentUnused]>;
+def fpredictive_compilation_def : Flag<"-fpredictive-compilation">, Group<f_Group>;
+def fpredictive_compilation_EQ : Joined<"-fpredictive-compilation=">, Group<f_Group>;
 def fprofile_arcs : Flag<"-fprofile-arcs">, Group<f_Group>;
 def fprofile_generate : Flag<"-fprofile-generate">, Group<f_Group>;
 def framework : Separate<"-framework">, Flags<[LinkerInput]>;
Index: lib/Frontend/CompilerInstance.cpp
===================================================================
--- lib/Frontend/CompilerInstance.cpp	(revision 139582)
+++ lib/Frontend/CompilerInstance.cpp	(working copy)
@@ -531,7 +531,7 @@
   // been created (e.g., by a precompiled preamble).
   if (!SourceMgr.getMainFileID().isInvalid()) {
     // Do nothing: the main file has already been set.
-  } else if (InputFile != "-") {
+  } else if (InputFile != "-" && Opts.PredictiveCompilation.empty()) {
     const FileEntry *File = FileMgr.getFile(InputFile);
     if (!File) {
       Diags.Report(diag::err_fe_error_reading) << InputFile;
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp	(revision 139582)
+++ lib/Frontend/CompilerInvocation.cpp	(working copy)
@@ -502,6 +502,10 @@
     Res.push_back("-mllvm");
     Res.push_back(Opts.LLVMArgs[i]);
   }
+  if (!Opts.PredictiveCompilation.empty()) {
+    Res.push_back("-fpredictive-compilation");
+    Res.push_back(Opts.PredictiveCompilation);
+  }
 }
 
 static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts,
@@ -1281,6 +1285,8 @@
   Opts.ShowVersion = Args.hasArg(OPT_version);
   Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge);
   Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
+  Opts.PredictiveCompilation
+    = Args.getLastArgValue(OPT_fpredictive_compilation);
   Opts.FixWhatYouCan = Args.hasArg(OPT_fix_what_you_can);
 
   Opts.ARCMTAction = FrontendOptions::ARCMT_None;
@@ -1913,4 +1919,11 @@
   ParsePreprocessorArgs(Res.getPreprocessorOpts(), *Args, FileMgr, Diags);
   ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), *Args);
   ParseTargetArgs(Res.getTargetOpts(), *Args);
+
+  // With -fpredictive-compilation, main file errors are reported not for
+  // <stdin> but for the input file, even though the input is read from stdin.
+  if (!Res.getFrontendOpts().PredictiveCompilation.empty()) {
+    Res.getDiagnosticOpts().FakeDiagMainFile
+      = Res.getFrontendOpts().Inputs[0].second;
+  }
 }
Index: lib/Frontend/TextDiagnosticPrinter.cpp
===================================================================
--- lib/Frontend/TextDiagnosticPrinter.cpp	(revision 139582)
+++ lib/Frontend/TextDiagnosticPrinter.cpp	(working copy)
@@ -954,17 +954,23 @@
                                               PresumedLoc PLoc) {
   if (PLoc.isInvalid()) {
     // At least print the file name if available:
-    FileID FID = SM.getFileID(Info.getLocation());
-    if (!FID.isInvalid()) {
-      const FileEntry* FE = SM.getFileEntryForID(FID);
-      if (FE && FE->getName()) {
-        OS << FE->getName();
-        if (FE->getDevice() == 0 && FE->getInode() == 0
-            && FE->getFileMode() == 0) {
-          // in PCH is a guess, but a good one:
-          OS << " (in PCH)";
+    if (SM.isFromMainFile(Info.getLocation()) &&
+        DiagOpts->FakeDiagMainFile.size()) {
+      // Use original input file name, even though we're reading from stdin.
+      OS << DiagOpts->FakeDiagMainFile << ": ";
+    } else {
+      FileID FID = SM.getFileID(Info.getLocation());
+      if (!FID.isInvalid()) {
+        const FileEntry* FE = SM.getFileEntryForID(FID);
+        if (FE && FE->getName()) {
+          OS << FE->getName();
+          if (FE->getDevice() == 0 && FE->getInode() == 0
+              && FE->getFileMode() == 0) {
+            // in PCH is a guess, but a good one:
+            OS << " (in PCH)";
+          }
+          OS << ": ";
         }
-        OS << ": ";
       }
     }
     return;
@@ -977,7 +983,13 @@
   if (DiagOpts->ShowColors)
     OS.changeColor(savedColor, true);
 
-  OS << PLoc.getFilename();
+  if (SM.isFromMainFile(Info.getLocation()) &&
+      DiagOpts->FakeDiagMainFile.size()) {
+    // Use original input file name, even though we're reading from stdin.
+    OS << DiagOpts->FakeDiagMainFile;
+  } else {
+    OS << PLoc.getFilename();
+  }
   switch (DiagOpts->Format) {
   case DiagnosticOptions::Clang: OS << ':'  << LineNo; break;
   case DiagnosticOptions::Msvc:  OS << '('  << LineNo; break;
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 139582)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -2022,6 +2022,25 @@
     CmdArgs.push_back(A->getValue(Args));
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ,
+                               options::OPT_Wlarge_by_value_copy_def)) {
+    CmdArgs.push_back("-Wlarge-by-value-copy");
+    if (A->getNumValues())
+      CmdArgs.push_back(A->getValue(Args));
+    else
+      CmdArgs.push_back("64"); // default value for -Wlarge-by-value-copy.
+  }
+
+  if (const Arg *A =
+        Args.getLastArg(options::OPT_fpredictive_compilation_EQ,
+                        options::OPT_fpredictive_compilation_def)) {
+    CmdArgs.push_back("-fpredictive-compilation");
+    if (A->getNumValues())
+      CmdArgs.push_back(A->getValue(Args));
+    else
+      CmdArgs.push_back("0");
+  }
+
   if (Arg *A = Args.getLastArg(
       options::OPT_fdiagnostics_show_note_include_stack,
       options::OPT_fno_diagnostics_show_note_include_stack)) {
