[Coroutines] Use LookupAllocationFunction to find allocation functions for coroutines...
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Mon, 5 Sep 2022 06:17:58 +0000 (14:17 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Mon, 5 Sep 2022 07:20:09 +0000 (15:20 +0800)
commit69e920d42677872ac39d3475312092404193bf24
treec2d5057008d70a69011098109867fdcae89e2ee7
parentfe70b17fcff043dee11f63a85941d3d927f59deb
[Coroutines] Use LookupAllocationFunction to find allocation functions for coroutines consistently

Previously we may call Sema::FindAllocationFunctions directly to lookup
allocation functions directly instead of using our wrapped lambda
LookupAllocationFunction, which is slightly incosnsistent. It will be
helpful to refactor this for further changes.

Also previously, when we lookup 'operator new(std::size_t, std::nothrow_t)' in
case we found `get_­return_­object_­on_­allocation_­failure` in the
promise_type, the compiler will try to look at the allocation function
in promise_type. However, this is not wanted actually. According to
[dcl.fct.def.coroutine]p10:

> if a global allocation function is selected, the
> ::operator new(size_­t, nothrow_­t) form is used.

So we should only lookup for `::operator (size_t, nothrow_t)` for the
global allocation function. For the allocation function in the
promise_type, the requirement is that it shouldn't throw, which has
already been checked.

Given users generally include headers from standard libs so it will
generally include the <new> header, so this change should be a trivial
one and shouldn't affect almost any user.
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaCoroutine.cpp
clang/test/SemaCXX/coroutine-alloc-2.cpp [new file with mode: 0644]
clang/test/SemaCXX/coroutine-alloc-3.cpp [new file with mode: 0644]