llvm / llvm/llvm-project

[CIR] Upstream missing support for exception handling edge cases

Open
#192,332 2 comments 0 reactions 0 assignees View on GitHub
ClangIR
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

### Overview

Edge cases in exception handling that are implemented in the incubator:
- **SEH / Borland exception check**: in `isInvokeDest()` /
`isCatchOrCleanupRequired()`, correctly checking `!LO.Borland &&
!LO.MicrosoftExt`, then further checking `currentFunctionUsesSEHTry()` and
CUDA device code, to properly determine whether invokes are needed when
exceptions are nominally disabled but SEH language extensions are enabled
- **ObjC catch parameter ownership**: falling through from
`OCL_ExplicitNone` and `OCL_Autoreleasing` to `OCL_None` in
`initCatchParam`, performing a plain `createStore` of the catch parameter
(these ownership qualifiers require no special ARC handling in the catch path)

Upstream NYI locations:
- `CIRGenException.cpp` — `isCatchOrCleanupRequired`: no exceptions but
Borland/MicrosoftExt enabled
- `CIRGenItaniumCXXABI.cpp` — `initCatchParam`:
`PointerRepresentation OCL_ExplicitNone & OCL_Autoreleasing`

### Suggested minimal test case

```cpp
// SEH exception handling (Windows-style, requires -fms-extensions)
// void test_seh() {
// __try {
// may_throw();
// } __except(1) {
// handle();
// }
// }

// The ObjC catch ownership edge case requires Objective-C++:
// @try {
// [obj method];
// } @catch (id __autoreleasing e) {
// // handle
// }
```

Note: These are niche edge cases. The SEH path requires `-fms-extensions` and
the ObjC catch path requires Objective-C++. Testing these requires specific
target and language mode configurations.

### Existing incubator tests

No specific tests for these edge cases were found in the incubator CodeGen
tests. The SEH and ObjC catch ownership paths are exercised only under specific
platform and language configurations not typically covered by CIR CodeGen tests.

Contributor guide

Open the contributing guide

Research direction

Start with CIRGenException.cpp:isCatchOrCleanupRequired and CIRGenItaniumCXXABI.cpp:initCatchParam, then compare the corresponding incubator behavior. Run the suggested SEH case with -fms-extensions and the Objective-C++ catch case under the required language and target configurations; done means both edge cases are supported and covered by appropriate tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.