Skip to content

Don't generate SEH scopes for noexcept functions #128839

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
20 changes: 18 additions & 2 deletions clang/lib/CodeGen/CGCleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ EHScopeStack::getInnermostActiveNormalCleanup() const {
return stable_end();
}

static bool FunctionCanThrow(const FunctionDecl *D) {
if (!D) {
return true;
}

const auto *Proto = D->getType()->getAs<FunctionProtoType>();
if (!Proto) {
// Function proto is not found, we conservatively assume throwing.
return true;
}
return !isNoexceptExceptionSpec(Proto->getExceptionSpecType()) ||
Proto->canThrow() != CT_Cannot;
}

void *EHScopeStack::pushCleanup(CleanupKind Kind, size_t Size) {
char *Buffer = allocate(EHCleanupScope::getSizeForCleanupSize(Size));
Expand Down Expand Up @@ -191,7 +204,9 @@ void *EHScopeStack::pushCleanup(CleanupKind Kind, size_t Size) {
// consistent with MSVC's behavior, except in the presence of -EHa.
// Check getInvokeDest() to generate llvm.seh.scope.begin() as needed.
if (CGF->getLangOpts().EHAsynch && IsEHCleanup && !IsLifetimeMarker &&
CGF->getTarget().getCXXABI().isMicrosoft() && CGF->getInvokeDest())
CGF->getTarget().getCXXABI().isMicrosoft() &&
FunctionCanThrow(dyn_cast<FunctionDecl>(CGF->CurFuncDecl)) &&
CGF->getInvokeDest())
CGF->EmitSehCppScopeBegin();

return Scope->getCleanupBuffer();
Expand Down Expand Up @@ -784,7 +799,8 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
cleanupFlags.setIsEHCleanupKind();

// Under -EHa, invoke seh.scope.end() to mark scope end before dtor
bool IsEHa = getLangOpts().EHAsynch && !Scope.isLifetimeMarker();
bool IsEHa = getLangOpts().EHAsynch && !Scope.isLifetimeMarker() &&
FunctionCanThrow(dyn_cast<FunctionDecl>(CurFuncDecl));
const EHPersonality &Personality = EHPersonality::get(*this);
if (!RequiresNormalCleanup) {
// Mark CPP scope end for passed-by-value Arg temp
Expand Down
Loading