mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 18:46:05 +00:00

I've taken the following steps to add unwinding support from inline assembly: 1) Add a new `unwind` "attribute" (like `sideeffect`) to the asm syntax: ``` invoke void asm sideeffect unwind "call thrower", "~{dirflag},~{fpsr},~{flags}"() to label %exit unwind label %uexit ``` 2.) Add Bitcode writing/reading support + LLVM-IR parsing. 3.) Emit EHLabels around inline assembly lowering (SelectionDAGBuilder + GlobalISel) when `InlineAsm::canThrow` is enabled. 4.) Tweak InstCombineCalls/InlineFunction pass to not mark inline assembly "calls" as nounwind. 5.) Add clang support by introducing a new clobber: "unwind", which lower to the `canThrow` being enabled. 6.) Don't allow unwinding callbr. Reviewed By: Amanieu Differential Revision: https://reviews.llvm.org/D95745
35 lines
896 B
C++
35 lines
896 B
C++
// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm -DUNWIND -fcxx-exceptions -fexceptions -o - %s | FileCheck -check-prefixes CHECK,CHECK-UNWIND %s
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-linux -emit-llvm -fcxx-exceptions -fexceptions -o - %s | FileCheck -check-prefixes CHECK,CHECK-NO-UNWIND %s
|
|
|
|
extern "C" void printf(const char *fmt, ...);
|
|
|
|
struct DropBomb {
|
|
bool defused = false;
|
|
|
|
~DropBomb() {
|
|
if (defused) {
|
|
return;
|
|
}
|
|
printf("Boom!\n");
|
|
}
|
|
};
|
|
|
|
extern "C" void trap() {
|
|
throw "Trap";
|
|
}
|
|
|
|
// CHECK: define dso_local void @test()
|
|
extern "C" void test() {
|
|
DropBomb bomb;
|
|
// CHECK-UNWIND: invoke void asm sideeffect unwind "call trap"
|
|
// CHECK-NO-UNWIND: call void asm sideeffect "call trap"
|
|
#ifdef UNWIND
|
|
asm volatile("call trap" ::
|
|
: "unwind");
|
|
#else
|
|
asm volatile("call trap" ::
|
|
:);
|
|
#endif
|
|
bomb.defused = true;
|
|
}
|