llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.41k stars 12.15k forks source link

Calling coroutines should be disallowed from [[nonallocating]] performance constraint setting #111050

Open cjappl opened 2 months ago

cjappl commented 2 months ago

C++20 coroutines allocate when beginning execution (source: Coroutines (C++20) - cppreference.com)

the coroutine state, which is internal, dynamically-allocated storage (unless the allocation is optimized out) …

… When a coroutine begins execution, it performs the following:

allocates the coroutine state object using operator new.

The new performance constraints attributes ([[clang::nonallocating]] and stricter) should detect and warn about coroutines being called from a nonallocating context.

CC @dougsonos (I can't assign you because you aren't a member, but consider yourself "assigned")

cjappl commented 2 months ago

I put up a PR with a test to ensure that RTSan catches these allocations:

https://github.com/llvm/llvm-project/pull/111049

llvmbot commented 2 months ago

@llvm/issue-subscribers-coroutines

Author: Chris Apple (cjappl)

C++20 coroutines allocate when beginning execution (source: [Coroutines (C++20) - cppreference.com](https://en.cppreference.com/w/cpp/language/coroutines)) >the coroutine state, which is internal, dynamically-allocated storage (unless the allocation is optimized out) … >… >When a coroutine begins execution, it performs the following: >[allocates](https://en.cppreference.com/w/cpp/language/coroutines#Dynamic_allocation) the coroutine state object using [operator new](https://en.cppreference.com/w/cpp/memory/new/operator_new). The new performance constraints attributes ([[clang::nonallocating]] and stricter) should detect and warn about coroutines being called from a nonallocating context. CC @dougsonos (I can't assign you because you aren't a member, but consider yourself "assigned")