================
@@ -1083,18 +1083,13 @@ void FactsGenerator::handleLifetimeCaptureBy(const 
FunctionDecl *FD,
 
 void FactsGenerator::handleFreeingCall(const Expr *Call, const FunctionDecl 
*FD,
                                        ArrayRef<const Expr *> Args) {
-  // FIXME: `ParamIdx` accounts for the implicit 'this' parameter of
-  // constructors, but VisitCXXConstructExpr passes only the explicit
-  // arguments, so the index mapping would be off by one.
-  if (isa<CXXConstructorDecl>(FD))
-    return;
   for (const OwnershipAttr *Attr : FD->specific_attrs<OwnershipAttr>()) {
     if (Attr->getOwnKind() != OwnershipAttr::Takes)
       continue;
     for (const ParamIdx &Idx : Attr->args()) {
-      // `getLLVMIndex` encodes zero-origin indices including any implicit
-      // 'this' parameter, matching the layout of the Args array.
-      unsigned ArgIndex = Idx.getLLVMIndex();
+      // Attribute indices count implicit 'this', but constructor Args omits 
it:
+      // the first explicit parameter (2) maps to Args[0], not Args[1].
+      unsigned ArgIndex = Idx.getLLVMIndex() - isa<CXXConstructorDecl>(FD);
----------------
NeKon69 wrote:

I could add that test case to `clang/test/Sema/attr-ownership.cpp` to ensure 
that this can't happen.

https://github.com/llvm/llvm-project/pull/213439
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to