diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b75404958..913d772126 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,9 @@ endif() option(DXC_DISABLE_ALLOCATOR_OVERRIDES "Disable usage of allocator overrides" OFF) mark_as_advanced(DXC_DISABLE_ALLOCATOR_OVERRIDES) +option(DXC_CODEGEN_EXCEPTIONS_TRAP "An exception in code generation generates a trap, ending the compiler process" OFF) +mark_as_advanced(DXC_CODEGEN_EXCEPTIONS_TRAP) + # adjust link option to enable debugging from kernel mode; not compatible with incremental linking if(NOT CMAKE_VERSION VERSION_LESS "3.13" AND MSVC AND NOT CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "ARM64EC") add_link_options(/DEBUGTYPE:CV,FIXUP,PDATA /INCREMENTAL:NO) diff --git a/include/dxc/config.h.cmake b/include/dxc/config.h.cmake index 6d7450323e..7226ed75a1 100644 --- a/include/dxc/config.h.cmake +++ b/include/dxc/config.h.cmake @@ -1,2 +1,4 @@ /* Disable overriding memory allocators. */ #cmakedefine DXC_DISABLE_ALLOCATOR_OVERRIDES +/* Generate a trap if an hlsl::Exception is thrown during code generation */ +#cmakedefine DXC_CODEGEN_EXCEPTIONS_TRAP diff --git a/tools/clang/lib/CodeGen/BackendUtil.cpp b/tools/clang/lib/CodeGen/BackendUtil.cpp index 1013d3149c..e552d8d124 100644 --- a/tools/clang/lib/CodeGen/BackendUtil.cpp +++ b/tools/clang/lib/CodeGen/BackendUtil.cpp @@ -8,6 +8,10 @@ //===----------------------------------------------------------------------===// #include "clang/CodeGen/BackendUtil.h" +#include "dxc/HLSL/DxilGenerationPass.h" // HLSL Change +#include "dxc/HLSL/HLMatrixLowerPass.h" // HLSL Change +#include "dxc/Support/Global.h" // HLSL Change +#include "dxc/config.h" // HLSL Change #include "clang/Basic/Diagnostic.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/TargetOptions.h" @@ -42,9 +46,6 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Utils/SymbolRewriter.h" #include -#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; @@ -782,6 +783,10 @@ void clang::EmitBackendOutput(DiagnosticsEngine &Diags, } catch (const ::hlsl::Exception &hlslException) { Diags.Report(Diags.getCustomDiagID(DiagnosticsEngine::Error, "%0\n")) << StringRef(hlslException.what()); +#if defined(DXC_CODEGEN_EXCEPTIONS_TRAP) + llvm::errs() << "internal error: " << hlslException.what() << "\n"; + LLVM_BUILTIN_TRAP; +#endif } // HLSL Change Ends // If an optional clang TargetInfo description string was passed in, use it to