- Notifications
You must be signed in to change notification settings - Fork 15.3k
[Clang] Mark this pointer in destructors dead_on_return #166276
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -2767,7 +2767,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 to aid in DSE. | ||
| // FIXME: fix this properly, https://reviews.llvm.org/D100388 | ||
| if (FI.isInstanceMethod() && !IRFunctionArgs.hasInallocaArg() && | ||
| !FI.arg_begin()->type->isVoidPointerType() && !IsThunk) { | ||
| | @@ -2800,6 +2801,15 @@ 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()); | ||
| if (ClassDecl->getNumBases() == 0 && ClassDecl->getNumVBases() == 0) { | ||
| Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have to limit this to only destructors of classes with no bases? Whatever the reason (caution, incremental change, etc), comments here would be appreciated. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Virtual base subobjects aren't dead after a base subobject destructor call, but yeah, I can't think of a reason to limit this because of non-virtual bases alone. And even virtual bases are dead after a complete-object destructor call. | ||
| Attrs.addAttribute(llvm::Attribute::DeadOnReturn); | ||
| } | ||
| } | ||
| | ||
| ArgAttrs[IRArgs.first] = llvm::AttributeSet::get(getLLVMContext(), Attrs); | ||
| } | ||
| | ||
| | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code golf: You can CSE the CalleeInfo.getCalleeDecl().getDecl() if you use dyn_cast_or_nonnull.