Sfoglia il codice sorgente

enable optimization passes to throw hlsl exceptions (#4427)

* enable optimization passes to throw hlsl exceptions to abort further compilation and capture relevant error data

* add HLSL change comments, and simplify Diagnostics data saving

* throw legalization exception, give more info when aborting

* change exception throw back to return, and remove error string
Joshua Batista 3 anni fa
parent
commit
b91ff3c586
1 ha cambiato i file con 10 aggiunte e 1 eliminazioni
  1. 10 1
      tools/clang/lib/CodeGen/BackendUtil.cpp

+ 10 - 1
tools/clang/lib/CodeGen/BackendUtil.cpp

@@ -43,6 +43,7 @@
 #include <memory>
 #include "dxc/HLSL/DxilGenerationPass.h" // HLSL Change
 #include "dxc/HLSL/HLMatrixLowerPass.h"  // HLSL Change
+#include "dxc/Support/Global.h" // HLSL Change
 
 using namespace clang;
 using namespace llvm;
@@ -762,7 +763,15 @@ void clang::EmitBackendOutput(DiagnosticsEngine &Diags,
                               raw_pwrite_stream *OS) {
   EmitAssemblyHelper AsmHelper(Diags, CGOpts, TOpts, LOpts, M);
 
-  AsmHelper.EmitAssembly(Action, OS);
+
+  try { // HLSL Change Starts
+    // Catch any fatal errors during optimization passes here
+    // so that future passes can be skipped.
+    AsmHelper.EmitAssembly(Action, OS);
+  } catch (const ::hlsl::Exception &hlslException) {
+    Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0\n"))
+        << StringRef(hlslException.what());
+  } // HLSL Change Ends
 
   // If an optional clang TargetInfo description string was passed in, use it to
   // verify the LLVM TargetMachine's DataLayout.