forked from OSchip/llvm-project
c651113439
Summary: https://bugs.llvm.org/show_bug.cgi?id=34897 demonstrates an incorrect coroutine frame allocation elision in the coro-elide pass. The elision is performed on the basis that the SSA variables from all llvm.coro.begin are directly referenced in subsequent llvm.coro.destroy instructions. However, this ignores the fact that the function may exit through paths that do not run these destroy instructions. In the sample program from PR34897, for example, the llvm.coro.destroy instruction is only executed in exception handling code. When the coroutine function exits normally, llvm.coro.destroy is not called. Eliding the allocation in this case causes a subsequent reference to the coroutine handle from outside of the function to access freed memory. To fix the issue, when finding an llvm.coro.destroy for each llvm.coro.begin, only consider llvm.coro.destroy that are executed along non-exceptional paths. Test Plan: 1. Download the sample program from https://bugs.llvm.org/show_bug.cgi?id=34897, compile it with `clang++ -fcoroutines-ts -stdlib=libc++ -std=c++1z -O2`, and run it. It should print `"run1\ncheck1\nrun2\ncheck2"` and then exit successfully. 2. Compile https://godbolt.org/g/mCKfnr and confirm it is still optimized to a single instruction, 'return 1190'. 3. `check-llvm` Reviewers: rsmith, GorNishanov, eric_niebler Reviewed By: GorNishanov Subscribers: andrewrk, lewissbaker, EricWF, llvm-commits Differential Revision: https://reviews.llvm.org/D43242 llvm-svn: 332077 |
||
---|---|---|
.. | ||
ArgAddr.ll | ||
coro-catchswitch.ll | ||
coro-cleanup.ll | ||
coro-debug.ll | ||
coro-early.ll | ||
coro-eh-aware-edge-split.ll | ||
coro-elide.ll | ||
coro-frame.ll | ||
coro-heap-elide.ll | ||
coro-materialize.ll | ||
coro-padding.ll | ||
coro-spill-after-phi.ll | ||
coro-spill-corobegin.ll | ||
coro-split-00.ll | ||
coro-split-01.ll | ||
coro-split-02.ll | ||
coro-split-alloc.ll | ||
coro-split-dbg.ll | ||
coro-split-eh.ll | ||
coro-split-hidden.ll | ||
coro-split-musttail.ll | ||
ex0.ll | ||
ex1.ll | ||
ex2.ll | ||
ex3.ll | ||
ex4.ll | ||
ex5.ll | ||
no-suspend.ll | ||
phi-coro-end.ll | ||
restart-trigger.ll | ||
smoketest.ll |