Skip to content

Conversation

bruteforceboy
Copy link
Contributor

Currently, the following code snippet fails with a crash during CodeGen

class C {
public:
  ~C();
  void operator=(C);
};

void d() {
  C a, b;
  a = b;
}

with error:

mlir::Block* clang::CIRGen::CIRGenFunction::getEHResumeBlock(bool, cir::TryOp): Assertion `tryOp && "expected available cir.try"' failed.

in CIRGenCleanup these lines don't check if there is a TryOp when at the end of the scope chain before getEHResumeBlock is called causing the crash, because it contains an assertion.

This PR fixes this and adds a simple test for a case like this.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, LGTM!

@bcardosolopes bcardosolopes merged commit 9f6742f into llvm:main Apr 17, 2025
10 checks passed
terapines-osc-cir pushed a commit to Terapines/clangir that referenced this pull request Sep 2, 2025
Currently, the following code snippet fails with a crash during CodeGen
```
class C {
public:
  ~C();
  void operator=(C);
};

void d() {
  C a, b;
  a = b;
}
```
with error: 
```
mlir::Block* clang::CIRGen::CIRGenFunction::getEHResumeBlock(bool, cir::TryOp): Assertion `tryOp && "expected available cir.try"' failed.
```
in CIRGenCleanup [these
lines](https://github.com/llvm/clangir/blob/204c03efbe898c9f64e477937d869767fdfb1310/clang/lib/CIR/CodeGen/CIRGenCleanup.cpp#L615C1-L617C6)
don't check if there is a TryOp when at the end of the scope chain
before
[getEHResumeBlock](https://github.com/llvm/clangir/blob/204c03efbe898c9f64e477937d869767fdfb1310/clang/lib/CIR/CodeGen/CIRGenException.cpp#L764)
is called causing the crash, because it contains an assertion.

This PR fixes this and adds a simple test for a case like this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants