| 
11 | 11 | #include "cling/MetaProcessor/MetaProcessor.h"  | 
12 | 12 | #include "cling/UserInterface/UserInterface.h"  | 
13 | 13 | 
 
  | 
14 |  | -#include "clang/Basic/LangOptions.h"  | 
15 |  | -#include "clang/Frontend/CompilerInstance.h"  | 
16 |  | -#include "clang/FrontendTool/Utils.h"  | 
17 |  | - | 
18 | 14 | #include "llvm/Support/Signals.h"  | 
19 | 15 | #include "llvm/Support/PrettyStackTrace.h"  | 
20 | 16 | #include "llvm/Support/ManagedStatic.h"  | 
 | 
28 | 24 | #include <crtdbg.h>  | 
29 | 25 | #endif  | 
30 | 26 | 
 
  | 
31 |  | -// If we are running with -verify a reported has to be returned as unsuccess.  | 
32 |  | -// This is relevant especially for the test suite.  | 
33 |  | -static int checkDiagErrors(clang::CompilerInstance* CI, unsigned* OutErrs = 0) {  | 
34 |  | - | 
35 |  | -  unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();  | 
36 |  | - | 
37 |  | -  if (CI->getDiagnosticOpts().VerifyDiagnostics) {  | 
38 |  | -    // If there was an error that came from the verifier we must return 1 as  | 
39 |  | -    // an exit code for the process. This will make the test fail as expected.  | 
40 |  | -    clang::DiagnosticConsumer* Client = CI->getDiagnostics().getClient();  | 
41 |  | -    Client->EndSourceFile();  | 
42 |  | -    Errs = Client->getNumErrors();  | 
43 |  | - | 
44 |  | -    // The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.  | 
45 |  | -    Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());  | 
46 |  | -  }  | 
47 |  | - | 
48 |  | -  if (OutErrs)  | 
49 |  | -    *OutErrs = Errs;  | 
50 |  | - | 
51 |  | -  return Errs ? EXIT_FAILURE : EXIT_SUCCESS;  | 
52 |  | -}  | 
53 |  | - | 
54 | 27 | 
 
  | 
55 | 28 | int main( int argc, char **argv ) {  | 
56 | 29 | 
 
  | 
@@ -83,18 +56,19 @@ int main( int argc, char **argv ) {  | 
83 | 56 |     if (Opts.Help || Opts.ShowVersion)  | 
84 | 57 |       return EXIT_SUCCESS;  | 
85 | 58 | 
 
  | 
86 |  | -    unsigned ErrsReported = 0;  | 
87 |  | -    if (clang::CompilerInstance* CI = Interp.getCIOrNull()) {  | 
88 |  | -      // If output requested and execution succeeded let the DiagnosticsEngine  | 
89 |  | -      // determine the result code  | 
90 |  | -      if (Opts.CompilerOpts.HasOutput && ExecuteCompilerInvocation(CI))  | 
91 |  | -        return checkDiagErrors(CI);  | 
 | 59 | +    using namespace cling;  | 
 | 60 | +    const Interpreter::CompilationResult ExecRes = Interp.executeInvocation();  | 
 | 61 | +    if (ExecRes != Interpreter::kFailure) {  | 
 | 62 | +      const int ErrsReported = Interp.verifyDiagnostics();  | 
92 | 63 | 
 
  | 
93 |  | -      checkDiagErrors(CI, &ErrsReported);  | 
94 |  | -    }  | 
 | 64 | +      // If output succeeded and diagnostics verified, we are done.  | 
 | 65 | +      if (ExecRes == Interpreter::kSuccess && !ErrsReported)  | 
 | 66 | +        return EXIT_SUCCESS;  | 
95 | 67 | 
 
  | 
96 |  | -    // If no errors have been reported, try perror  | 
97 |  | -    if (ErrsReported == 0)  | 
 | 68 | +      // FIXME: This info is barely useful  | 
 | 69 | +      if (ErrsReported <= 0)  | 
 | 70 | +        ::fprintf(stderr, "Unknown error");  | 
 | 71 | +    } else  | 
98 | 72 |       ::perror("Could not create Interpreter instance");  | 
99 | 73 | 
 
  | 
100 | 74 |     return EXIT_FAILURE;  | 
@@ -138,5 +112,5 @@ int main( int argc, char **argv ) {  | 
138 | 112 |   ::fflush(stdout);  | 
139 | 113 |   ::fflush(stderr);  | 
140 | 114 | 
 
  | 
141 |  | -  return checkDiagErrors(Interp.getCI());  | 
 | 115 | +  return Interp.verifyDiagnostics() ? EXIT_FAILURE : EXIT_SUCCESS;  | 
142 | 116 | }  | 
0 commit comments