================
@@ -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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to