[WinEH] Apply funclet operand bundles to nounwind intrinsics that lower to function...
authorStefan Gränitz <stefan.graenitz@gmail.com>
Tue, 26 Jul 2022 09:40:48 +0000 (11:40 +0200)
committerStefan Gränitz <stefan.graenitz@gmail.com>
Tue, 26 Jul 2022 15:52:43 +0000 (17:52 +0200)
commit1e308204838b5edc5ffbd775896a004edb08c60a
tree7caf76337be9414026ef1ac577ce98296f11a998
parent75b15a7e63d9d31b5191afa49e38439dfe12bd40
[WinEH] Apply funclet operand bundles to nounwind intrinsics that lower to function calls in the course of IR transforms

WinEHPrepare marks any function call from EH funclets as unreachable, if it's not a nounwind intrinsic or has no proper funclet bundle operand. This
affects ARC intrinsics on Windows, because they are lowered to regular function calls in the PreISelIntrinsicLowering pass. It caused silent binary truncations and crashes during unwinding with the GNUstep ObjC runtime: https://github.com/gnustep/libobjc2/issues/222

This patch adds a new function `llvm::IntrinsicInst::mayLowerToFunctionCall()` that aims to collect all affected intrinsic IDs.
* Clang CodeGen uses it to determine whether or not it must emit a funclet bundle operand.
* PreISelIntrinsicLowering asserts that the function returns true for all ObjC runtime calls it lowers.
* LLVM uses it to determine whether or not a funclet bundle operand must be propagated to inlined call sites.

Reviewed By: theraven

Differential Revision: https://reviews.llvm.org/D128190
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGenObjCXX/arc-exceptions-seh.mm [new file with mode: 0644]
llvm/include/llvm/IR/IntrinsicInst.h
llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
llvm/lib/IR/IntrinsicInst.cpp
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/CodeGen/X86/win64-funclet-preisel-intrinsics.ll [new file with mode: 0644]
llvm/test/Feature/OperandBundles/inliner-funclet-wineh.ll [new file with mode: 0644]