Skip to content

Commit

Permalink
[CodeGen] Make __clang_call_terminate have an unwind table entry
Browse files Browse the repository at this point in the history
This enables unwinders to step past that frame on architectures that
don't use DWARF unwinding (such as armv7), e.g. when debugging. The
problem should theoretically be architecture-agnostic, but according to
https://discourse.llvm.org/t/51633/2 it gets masked on architectures
that use DWARF unwind info.

Fixes #40696

Reviewed By: efriedma, rnk

Differential Revision: https://reviews.llvm.org/D151393
  • Loading branch information
smeenai committed May 25, 2023
1 parent 023504f commit 8f7b51e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions clang/lib/CodeGen/ItaniumCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4689,6 +4689,7 @@ static llvm::FunctionCallee getClangCallTerminateFn(CodeGenModule &CGM) {
cast<llvm::Function>(fnRef.getCallee()->stripPointerCasts());
if (fn->empty()) {
CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, fn, /*IsThunk=*/false);
CGM.SetLLVMFunctionAttributesForDefinition(nullptr, fn);
fn->setDoesNotThrow();
fn->setDoesNotReturn();

Expand Down
15 changes: 15 additions & 0 deletions clang/test/CodeGenCXX/clang-call-terminate.uwtable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %clang_cc1 -triple=x86_64-linux-gnu -fexceptions -fcxx-exceptions -emit-llvm -o - %s | \
// RUN: FileCheck --check-prefixes=CHECK,NOUNWIND %s
// RUN: %clang_cc1 -triple=x86_64-linux-gnu -fexceptions -fcxx-exceptions -funwind-tables=1 -emit-llvm -o - %s | \
// RUN: FileCheck --check-prefixes=CHECK,SYNCUNWIND %s
// RUN: %clang_cc1 -triple=x86_64-linux-gnu -fexceptions -fcxx-exceptions -funwind-tables=2 -emit-llvm -o - %s | \
// RUN: FileCheck --check-prefixes=CHECK,ASYNCUNWIND %s

void caller(void callback()) noexcept { callback(); }

// CHECK: define {{.*}}void @__clang_call_terminate({{[^)]*}}) #[[#ATTRNUM:]]
// CHECK: attributes #[[#ATTRNUM]] = {
// NOUNWIND-NOT: uwtable
// NOUNWIND-SAME: }
// SYNCUNWIND-SAME: uwtable(sync)
// ASYNCUNWIND-SAME: uwtable{{ }}

0 comments on commit 8f7b51e

Please sign in to comment.