llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-coroutines

Author: Alina Sbirlea (alinas)

<details>
<summary>Changes</summary>

Fix error occuring with couroutines:
"error: too many arguments to function call, expected 3, have 4" for operator 
new.

Introduced by cd67cfecb1a1.

AI assisted explanation of the issue:
Prior to cd67cfecb1a1, Sema::FindAllocationFunctions took OperatorNew by 
reference and would unconditionally reset it to nullptr at the beginning of its 
search. The commit changed FindAllocationFunctions to return a 
std::optional&lt;ResolvedAllocation&gt;.

In clang/lib/Sema/SemaCoroutine.cpp, the result is handled like this:

   1     IAP = ImplicitAllocationParameters(
   2         alignedAllocationModeFromBool(ShouldUseAlignedAlloc));
   3
   4     auto FoundAllocations = S.FindAllocationFunctions(...);
   5     if (FoundAllocations) {
   6       IAP = FoundAllocations-&gt;IAP;
   7       OperatorNew = FoundAllocations-&gt;OperatorNew;
   8     }

  If the coroutine promise defines an unaligned operator new(size_t, void*, 
size_t), the first lookup succeeds but is considered unaligned
  (IAP.PassAlignment resolves to No). Because aligned allocation is enabled by 
default, the coroutine builder attempts a second lookup without placement
  arguments:

   1     if (!OperatorNew || (S.getLangOpts().CoroAlignedAllocation &amp;&amp;
   2                          !isAlignedAllocation(IAP.PassAlignment)))
   3       LookupAllocationFunction(/*NewScope*/ AllocationFunctionScope::Class,
   4                                /*WithoutPlacementArgs*/ true);

  When this second lookup runs, it resets IAP.PassAlignment to Yes at the start 
of the lambda. However, if this second lookup fails to find an aligned
  operator new, FindAllocationFunctions returns std::nullopt.

  Because FoundAllocations is empty, OperatorNew is never reset to nullptr, and 
IAP is never reset to No. They leak state:
   - OperatorNew retains the result from the first successful lookup (which 
takes 3 parameters).
   - IAP.PassAlignment retains the initialized Yes from the second failed 
lookup.

---
Full diff: https://github.com/llvm/llvm-project/pull/215619.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaCoroutine.cpp (+2) 


``````````diff
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index aceb5f2aa33a4..48ee5cc0b0836 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -1488,6 +1488,8 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
     if (FoundAllocations) {
       IAP = FoundAllocations->IAP;
       OperatorNew = FoundAllocations->OperatorNew;
+    } else {
+      OperatorNew = nullptr;
     }
     assert(!OperatorNew || !OperatorNew->isTypeAwareOperatorNewOrDelete());
   };

``````````

</details>


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

Reply via email to