[driver] Do emit the diagnostics when CompilerInvocation::CreateFromArgs() fails.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148970 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Driver/unknown-arg.c b/test/Driver/unknown-arg.c
new file mode 100644
index 0000000..5d0f7af
--- /dev/null
+++ b/test/Driver/unknown-arg.c
@@ -0,0 +1,4 @@
+// RUN: not %clang_cc1 %s -cake-is-lie 2> %t.log
+// RUN: FileCheck %s -input-file=%t.log
+
+// CHECK: unknown argument
diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp
index 0a14fdd..ad3f350 100644
--- a/tools/driver/cc1_main.cpp
+++ b/tools/driver/cc1_main.cpp
@@ -140,8 +140,6 @@
   bool Success;
   Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(),
                                                ArgBegin, ArgEnd, Diags);
-  if (!Success)
-    return 1;
 
   // Infer the builtin include path if unspecified.
   if (Clang->getHeaderSearchOpts().UseBuiltinIncludes &&
@@ -160,6 +158,8 @@
                                   static_cast<void*>(&Clang->getDiagnostics()));
 
   DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
+  if (!Success)
+    return 1;
 
   // Execute the frontend actions.
   Success = ExecuteCompilerInvocation(Clang.get());