[clang] [WinEH] Fix crash, object unwinding in the except block (PR #172287)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 22 20:00:13 PST 2025
GkvJwa wrote:
> @GkvJwa I don't understand the added message in your last comment. [Previously](https://github.com/llvm/llvm-project/pull/172287#discussion_r2635384617) you already identified the call stack which tells us how pushCleanup is called. `NormalAndEHCleanup` does really mean it is a `NormalCleanup` + `EHCleanup` so yes the code is executed -> thats really how the problematic `seh.scope.begin` gets emitted for your case which causes the issue: https://godbolt.org/z/hKW6vroeY .
What I'm trying to say is that with SEH enabled, `EmitCXXTemporary` in the `__try/__except` block should not actually be called.
`EmitCXXTemporary` executes `pushDestroy` to pass `NormalAndEHCleanup`
```
void CodeGenFunction::EmitCXXTemporary(const CXXTemporary *Temporary,
QualType TempType,
Address Ptr) {
pushDestroy(NormalAndEHCleanup, Ptr, TempType, destroyCXXObject,
/*useEHCleanup*/ true);
}
```
However, if we consider handling this within `pushCleanup`, Could it be misjudged as a normal use of `(pushCleanup + NormalAndEHCleanup)`?
This led me to wonder before if it was possible to make a judgment directly in this way.
```
void *EHScopeStack::pushCleanup(CleanupKind Kind, size_t Size) {
...
if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
CGF->getTarget().getCXXABI().isMicrosoft() && CGF->getInvokeDest()) {
if (IsNormalCleanup) {
CGF->CGM.getDiags().Report(CGF->CurFuncDecl->getLocation(),
diag::err_seh_expected_handler);
}
}
CGF->EmitSehCppScopeBegin();
}
```
I may communicate via code in the future (you can do that too), as there might be some misunderstandings in the text.
https://github.com/llvm/llvm-project/pull/172287
More information about the cfe-commits
mailing list