[clang] 8f7b51e - [CodeGen] Make __clang_call_terminate have an unwind table entry
Shoaib Meenai via cfe-commits
cfe-commits at lists.llvm.org
Thu May 25 10:57:40 PDT 2023
Author: Shoaib Meenai
Date: 2023-05-25T10:56:23-07:00
New Revision: 8f7b51e4ec09f6f50ea6508a196ec607f0659179
URL: https://github.com/llvm/llvm-project/commit/8f7b51e4ec09f6f50ea6508a196ec607f0659179
DIFF: https://github.com/llvm/llvm-project/commit/8f7b51e4ec09f6f50ea6508a196ec607f0659179.diff
LOG: [CodeGen] Make __clang_call_terminate have an unwind table entry
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 https://github.com/llvm/llvm-project/issues/40696
Reviewed By: efriedma, rnk
Differential Revision: https://reviews.llvm.org/D151393
Added:
clang/test/CodeGenCXX/clang-call-terminate.uwtable.cpp
Modified:
clang/lib/CodeGen/ItaniumCXXABI.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 668660124c74..5dc21dd31e0a 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -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();
diff --git a/clang/test/CodeGenCXX/clang-call-terminate.uwtable.cpp b/clang/test/CodeGenCXX/clang-call-terminate.uwtable.cpp
new file mode 100644
index 000000000000..ebf21c635da0
--- /dev/null
+++ b/clang/test/CodeGenCXX/clang-call-terminate.uwtable.cpp
@@ -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{{ }}
More information about the cfe-commits
mailing list