[FunctionAttrs] Fix nounwind inference for landingpads
authorNikita Popov <npopov@redhat.com>
Thu, 6 Apr 2023 08:49:42 +0000 (10:49 +0200)
committerNikita Popov <npopov@redhat.com>
Fri, 14 Apr 2023 09:46:00 +0000 (11:46 +0200)
commit9fe78db4cd1c18fc36a2f2bcc849adf2941027ba
tree40e73997c039f768affae2dd43878217df46126e
parent677b0d33e383fa104530c03e38601219c2aa82f9
[FunctionAttrs] Fix nounwind inference for landingpads

Currently, FunctionAttrs treats landingpads as non-throwing, and
will infer nounwind for functions with landingpads (assuming they
can't unwind in some other way, e.g. via resum). There are two
problems with this:

* Non-cleanup landingpads with catch/filter clauses do not
  necessarily catch all exceptions. Unless there are catch ptr null
  or filter [0 x ptr] zeroinitializer clauses, we should assume
  that we may unwind past this landingpad. This seems like an
  outright bug.
* Cleanup landingpads are skipped during phase one unwinding, so
  we effectively need to support unwinding past them. Marking these
  nounwind is technically correct, but not compatible with how
  unwinding works in reality.

Fixes https://github.com/llvm/llvm-project/issues/61945.

Differential Revision: https://reviews.llvm.org/D147694
llvm/include/llvm/IR/Instruction.h
llvm/lib/IR/Instruction.cpp
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/test/Transforms/Attributor/nocapture-1.ll
llvm/test/Transforms/FunctionAttrs/nounwind.ll