Index: tools/clang/lib/Frontend/FrontendAction.cpp
==================================================================
--- tools/clang/lib/Frontend/FrontendAction.cpp
+++ tools/clang/lib/Frontend/FrontendAction.cpp
@@ -160,10 +160,11 @@
   assert(!Instance && "Already processing a source file!");
   assert(!Input.File.empty() && "Unexpected empty filename!");
   setCurrentInput(Input);
   setCompilerInstance(&CI);
 
+  bool HasBegunSourceFile = false;
   if (!BeginInvocation(CI))
     goto failure;
 
   // AST files follow a very different path, since they share objects via the
   // AST unit.
@@ -212,10 +213,11 @@
     assert(hasIRSupport() &&
            "This action does not have IR file support!");
 
     // Inform the diagnostic client we are processing a source file.
     CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), 0);
+    HasBegunSourceFile = true;
 
     // Initialize the action.
     if (!BeginSourceFileAction(CI, Input.File))
       goto failure;
 
@@ -226,10 +228,11 @@
   CI.createPreprocessor();
 
   // Inform the diagnostic client we are processing a source file.
   CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(),
                                            &CI.getPreprocessor());
+  HasBegunSourceFile = true;
 
   // Initialize the action.
   if (!BeginSourceFileAction(CI, Input.File))
     goto failure;
 
@@ -307,11 +310,12 @@
     CI.setPreprocessor(0);
     CI.setSourceManager(0);
     CI.setFileManager(0);
   }
 
-  CI.getDiagnosticClient().EndSourceFile();
+  if (HasBegunSourceFile)
+    CI.getDiagnosticClient().EndSourceFile();
   setCurrentInput(FrontendInputFile());
   setCompilerInstance(0);
   return false;
 }
 

