Skip to content

[SEH] Fix assertin when return scalar value from __try block. #71488

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 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3507,6 +3507,9 @@ static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) {
return nullptr;
// These aren't actually possible for non-coerced returns, and we
// only care about non-coerced returns on this code path.
// All memory instructions inside __try block are volatile.
if (CGF.currentFunctionUsesSEHTry() && SI->isVolatile())
return SI;
assert(!SI->isAtomic() && !SI->isVolatile());
return SI;
};
Expand Down
23 changes: 23 additions & 0 deletions clang/test/CodeGen/windows-seh-EHa-TryInFinally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,26 @@ void foo()
}
}
}

// CHECK-LABEL:@"?bar@@YAHXZ"()
// CHECK: invoke.cont:
// CHECK: invoke void @llvm.seh.try.begin()
// CHECK: invoke.cont1:
// CHECK: store volatile i32 1, ptr %cleanup.dest.slot
// CHECK: invoke void @llvm.seh.try.end()
// CHECK: invoke.cont2:
// CHECK: call void @"?fin$0@0@bar@@"
// CHECK: %cleanup.dest3 = load i32, ptr %cleanup.dest.slot
// CHECK: return:
// CHECK: ret i32 11
int bar()
{
int x;
__try {
return 11;
} __finally {
if (_abnormal_termination()) {
x = 9;
}
}
}