Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake option DXC_CODEGEN_EXCEPTIONS_TRAP #6764

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/dxc/config.h.cmake
Original file line number Diff line number Diff line change
@@ -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
15 changes: 12 additions & 3 deletions tools/clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -41,10 +45,8 @@
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/SymbolRewriter.h"
#include <cstdio>
#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;
Expand Down Expand Up @@ -782,6 +784,13 @@ 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() doesn't work in release builds on Linux.
dneto0 marked this conversation as resolved.
Show resolved Hide resolved
// Use C-style fprintf because it works everywhere.
fprintf(stderr, "internal codegen error: %s\n", hlslException.what());
fflush(stderr);
LLVM_BUILTIN_TRAP;
#endif
} // HLSL Change Ends

// If an optional clang TargetInfo description string was passed in, use it to
Expand Down
Loading