[clang] [clang][CodeGen] Set `dead_on_return` on indirect pointer arguments (PR #148159)
Antonio Frighetto via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 15 06:17:34 PDT 2025
================
@@ -2852,8 +2852,17 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
if (AI.getInReg())
Attrs.addAttribute(llvm::Attribute::InReg);
- if (AI.getIndirectByVal())
+ // Depending on the ABI, this may be either a byval or a dead_on_return
+ // argument.
+ if (AI.getIndirectByVal()) {
Attrs.addByValAttr(getTypes().ConvertTypeForMem(ParamType));
+ } else {
+ // If the argument type has a non-trivial destructor that the caller has
+ // to invoke, this cannot be a dead_on_return argument.
+ const auto *RD = ParamType->getAsCXXRecordDecl();
+ if (!RD || (RD && RD->hasTrivialDestructor()))
+ Attrs.addAttribute(llvm::Attribute::DeadOnReturn);
+ }
----------------
antoniofrighetto wrote:
Thank you for clarifying this, updated it. Tests updated too (it indeed looks like from the tests that some MSVC callee-destroyed objects, which are passed indirectly, should be dead_on_return. So is the case for Obj-C++ structs, as mentioned, with __weak and __strong references, as per `objc-struct-cxx-abi.mm` and `ptrauth-struct-cxx-abi.mm` tests).
https://github.com/llvm/llvm-project/pull/148159
More information about the cfe-commits
mailing list