Skip to content
Draft
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
15 changes: 14 additions & 1 deletion clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2765,7 +2765,8 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
}

// Apply `nonnull`, `dereferenceable(N)` and `align N` to the `this` argument,
// unless this is a thunk function.
// unless this is a thunk function. Add dead_on_return to the `this` argument
// in base class destructors.
// FIXME: fix this properly, https://reviews.llvm.org/D100388
if (FI.isInstanceMethod() && !IRFunctionArgs.hasInallocaArg() &&
!FI.arg_begin()->type->isVoidPointerType() && !IsThunk) {
Expand Down Expand Up @@ -2798,6 +2799,18 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
.getAsAlign();
Attrs.addAlignmentAttr(Alignment);

if (isa_and_nonnull<CXXDestructorDecl>(
CalleeInfo.getCalleeDecl().getDecl())) {
auto *ClassDecl = dyn_cast<CXXRecordDecl>(
CalleeInfo.getCalleeDecl().getDecl()->getDeclContext());
assert(
ClassDecl &&
"Expected CXXDestructorDecl to have a CXXRecordDecl as its parent.");
if (ClassDecl->getNumBases() == 0 && ClassDecl->getNumVBases() == 0) {
Attrs.addAttribute(llvm::Attribute::DeadOnReturn);
}
}

ArgAttrs[IRArgs.first] = llvm::AttributeSet::get(getLLVMContext(), Attrs);
}

Expand Down
Loading