This patch adds typeid lowering, which uses a lot of the infrastructure
from dynamic_cast. However, this adds a `get_type_info` operation that
gets the type info out of a vtable pointer as well, which lets the
offset be handled by the ABI specific lowering code.
We had a problem where scope terminators were not being created
correctly when a cleanup scope appeared inside the body of a try
operation. This was caused by cleanup scope operation not being properly
flushed before the try body scope was completed.
This change fixes the problem by creating a RunCleanupsScope in the
lambda that pupulates the try body and forcing cleanups before adding
the yield terminator to the try body.
The test case also exposed a secondary bug where we were not properly
updating the innermostEHScope variable when popping a cleanup from the
eh stack. That is also fixed here.
This updates the cir::ResumeOp operation to require an EH token operand.
We already had the token available at both locations where the operation
was being created. Adding this operand makes finding the token more
robust during CFG flattening.
This change was entirely AI generated, but I have reviewed it closely.
This updates the design for catch handler regions in CIR try operations
to add an EH token argument to the regions and to use the
`cir.begin_catch` and `cir.end_catch` operations in the structured
representation rather than a `cir.catch_param`. This matches the
flattened representation and will make flattening easier to implement.
This leaves the generation of begin_catch and end_catch operands in the
`CXXABI` interface and Itanium implementation. However, because this
representation is no longer target-specific, I intend to move this code
to `CIRGenFunction` in a future change.
I used AI tools to generate many of the changes in this PR, but I have
carefully reviewed the changes and updated as needed.
With the new exception handling device, we no longer need to track the
location of potential catch blocks, and so we no longer need to
represent catch handlers on the EH stack. This allows us to
significantly simplify the generation of try-catch blocks.
This change emits catch blocks directly when visiting the try operation
and removes unnecessary EH management code.
This is not an exhaustive cleanup of the EH management code. Some things
that may appear to be obvious simplifications (such as removing the
union of bitfields in EHScope, and possibly making EHScopeStack just a
stack of EHCleanups) are deferred until we have a better idea of how
things like EH filters will be implemented.
This change breaks lowering of cir.try operations to LLVM IR in a
somewhat trivial way. Even before this PR, lowering of `cir.try` ops
with catch handlers was not implemented. However, we had one test case
where the only call in a try-region was marked with the `noexcept`
attribute. Previously, we did not emit catch handlers in that
circumstance. Now we do. As such, nothing that previously worked is
broken by this patch, but there is one test that would now fail. I
handled this by removing the RUN line for lowering this test to LLVM IR.
I left the checks so this will be easy to re-enable when proper try-op
lowering is implemented.
Upstream the basic support for the C++ try catch statement with a try
block that doesn't contain any call instructions and with a catch-all
statement
Issue #154992