Skip to content

Commit 2e07469

Browse files
committed
Always use getCanonicalDecl() and avoid emitting branch with unreachable
1 parent d945d0e commit 2e07469

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

clang/include/clang/AST/DeclCXX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,7 @@ class CXXDestructorDecl : public CXXMethodDecl {
28922892
}
28932893

28942894
void setOperatorGlobalDelete(FunctionDecl *OD) {
2895-
auto *First = cast<CXXDestructorDecl>(getFirstDecl());
2895+
auto *First = cast<CXXDestructorDecl>(getCanonicalDecl());
28962896
if (OD && !First->OperatorGlobalDelete)
28972897
First->OperatorGlobalDelete = OD;
28982898
}

clang/lib/CodeGen/CGClass.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,8 @@ namespace {
16351635
// If Sema only found a global operator delete previously, the dtor can
16361636
// always call it. Otherwise we need to check the third bit and call the
16371637
// appropriate operator delete, i.e. global or class-specific.
1638-
if (isa<CXXMethodDecl>(OD)) {
1638+
if (const FunctionDecl *GlobOD = Dtor->getOperatorGlobalDelete();
1639+
isa<CXXMethodDecl>(OD) && GlobOD) {
16391640
// Third bit set signals that global operator delete is called, i.e.
16401641
// ::delete appears on the callsite.
16411642
llvm::Value *CheckTheBitForGlobDeleteCall = CGF.Builder.CreateAnd(
@@ -1649,12 +1650,7 @@ namespace {
16491650
CGF.Builder.CreateCondBr(ShouldCallGlobDelete, ClassDelete, GlobDelete);
16501651
CGF.EmitBlock(GlobDelete);
16511652

1652-
const FunctionDecl *GlobOD = Dtor->getOperatorGlobalDelete();
1653-
if (GlobOD)
1654-
EmitDeleteAndGoToEnd(GlobOD);
1655-
else
1656-
CGF.Builder.CreateUnreachable();
1657-
1653+
EmitDeleteAndGoToEnd(GlobOD);
16581654
CGF.EmitBlock(ClassDelete);
16591655
}
16601656
EmitDeleteAndGoToEnd(OD);

0 commit comments

Comments
 (0)