Skip to content

[CIR][Transforms] Fix flattening for TryOp with empty catch region #1646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025

Conversation

bruteforceboy
Copy link
Contributor

@bruteforceboy bruteforceboy commented May 27, 2025

Currently, the following code snippet crashes during flattening, before lowering to llvm:

struct S {
  int a, b;
};

void foo() {
  try {
    S s{1, 2};
  } catch (...) {
  }
}

Command to reproduce:

clang tmp.cpp -Xclang -fclangir -Xclang -emit-cir-flat -S -o -

The crash happens when flattening a TryOp with an empty catch region and building catchers. Something like:

"cir.try"() ({
}, {
}) : () -> ()

the crash happens at tryOp.isCatchAllOnly() to be specific, because the catch types attribute list is empty.

The fix is simple - adding a check for an empty/non-existent catch region before building the catch clauses.

This PR adds this fix and one test.

Side-note: This enables push_back for std::vector to be lowered to llvm, for example:

#include <vector>

void foo() {
  std::vector<int> v;
  v.push_back(1);
}

@bcardosolopes bcardosolopes merged commit 16718e6 into llvm:main May 27, 2025
10 checks passed
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