Skip to content

[clang][sema]: Error when SEH __try is used in a function with C++ dtors #151836

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Qwinci
Copy link
Contributor

@Qwinci Qwinci commented Aug 2, 2025

Don't generate calls to llvm.seh.scope.{begin,end} if c++ exceptions are disabled. Currently clang sometimes causes LLVM to crash due to invalid usage of the seh intrinsics when c++ objects with destructors are in scope with __try/__except when using -fasync-exceptions (see #82917). I am not sure why the assert that I removed fails with the changes, it would be nice if someone who knows more about the seh code would comment on this. CC @phoebewang
Add a sema check to make sure that there are no C++ objects with non-trivial destructors in a function where SEH __try is used.

@phoebewang
Copy link
Contributor

Is the problem happening when enabling async-exceptions but not cxx-exceptions on c++ objects? I'm not sure if it's a valid scenario. The designed requires cxx-exceptions, see descriptions in 797ad70

Maybe we can emit an error for such case instead?

@Qwinci
Copy link
Contributor Author

Qwinci commented Aug 3, 2025

Is the problem happening when enabling async-exceptions but not cxx-exceptions on c++ objects? I'm not sure if it's a valid scenario. The designed requires cxx-exceptions, see descriptions in 797ad70

Maybe we can emit an error for such case instead?

Actually yeah my bad, looks like its invalid on MSVC to have objects with destructors in a function where __try/__except are used. Ill see if I can change this to be a check for that instead (and this is unrelated to exceptions being enabled, at least in my experience the C style seh __try/__except work just fine with async-exceptions + cxx exceptions disabled, I'd like to keep it that way as I use them in bare-metal C++ code where enabling c++ exceptions is undesirable plus async-exceptions should be usable in C code too).

@Qwinci Qwinci force-pushed the clang/fix-seh-scope-end branch from 1397a14 to 858ae7e Compare August 3, 2025 13:20
@Qwinci Qwinci changed the title [clang][seh]: Fix c++ destructors when c++ exceptions are disabled [clang][sema]: Error when SEH __try is used in a function with C++ dtors Aug 3, 2025
@Qwinci Qwinci force-pushed the clang/fix-seh-scope-end branch from 858ae7e to 472cdf4 Compare August 3, 2025 13:23
SEH __try is not allowed in a function with C++ objects that have non-trivial
destructors.
@Qwinci Qwinci force-pushed the clang/fix-seh-scope-end branch from 472cdf4 to 5d6cdac Compare August 3, 2025 13:47
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