clover: Use Clang's diagnostics
authorVedran Miletić <vedran@miletic.net>
Wed, 21 Dec 2016 12:49:36 +0000 (13:49 +0100)
committerFrancisco Jerez <currojerez@riseup.net>
Sun, 25 Dec 2016 02:35:09 +0000 (18:35 -0800)
Presently errors from frontend are handled only if they occur in
clang::CompilerInvocation::CreateFromArgs(). This patch uses
clang::DiagnosticsEngine to detect errors such as invalid values for
Clang frontend arguments.

Fixes Piglit's cl/program/build/fail/invalid-version-declaration.cl
test.

v2: fix inconsistent code formatting

Signed-off-by: Vedran Miletić <vedran@miletic.net>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
Tested-by: Aaron Watry <awatry@gmail.com>
src/gallium/state_trackers/clover/llvm/invocation.cpp

index 675cf1944d75839a22f057b232ceaf7952ab90fc..f63ff3d41c3fe4d4fbf17ba81a1c7b84e5a16969 100644 (file)
@@ -98,8 +98,9 @@ namespace {
                             const std::vector<std::string> &opts,
                             std::string &r_log) {
       std::unique_ptr<clang::CompilerInstance> c { new clang::CompilerInstance };
+      clang::TextDiagnosticBuffer *diag_buffer = new clang::TextDiagnosticBuffer;
       clang::DiagnosticsEngine diag { new clang::DiagnosticIDs,
-            new clang::DiagnosticOptions, new clang::TextDiagnosticBuffer };
+            new clang::DiagnosticOptions, diag_buffer };
 
       // Parse the compiler options.  A file name should be present at the end
       // and must have the .cl extension in order for the CompilerInvocation
@@ -111,6 +112,10 @@ namespace {
              c->getInvocation(), copts.data(), copts.data() + copts.size(), diag))
          throw invalid_build_options_error();
 
+      diag_buffer->FlushDiagnostics(diag);
+      if (diag.hasErrorOccurred())
+         throw invalid_build_options_error();
+
       c->getTargetOpts().CPU = target.cpu;
       c->getTargetOpts().Triple = target.triple;
       c->getLangOpts().NoBuiltin = true;