hanchenye-llvm-project/llvm/test/Transforms/Coroutines
Brian Gesiak c651113439 [Coroutines] PR34897: Fix incorrect elisions
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
2018-05-11 03:12:28 +00:00
..
ArgAddr.ll
coro-catchswitch.ll
coro-cleanup.ll
coro-debug.ll [DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label. 2018-05-09 02:40:45 +00:00
coro-early.ll
coro-eh-aware-edge-split.ll
coro-elide.ll
coro-frame.ll
coro-heap-elide.ll [Coroutines] PR34897: Fix incorrect elisions 2018-05-11 03:12:28 +00:00
coro-materialize.ll
coro-padding.ll [coroutines] Respect alloca alignment requirements when building coroutine frame 2018-04-03 20:54:20 +00:00
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 [DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label. 2018-05-09 02:40:45 +00:00
coro-split-eh.ll
coro-split-hidden.ll [Coroutines] Avoid assert splitting hidden coros 2018-04-02 23:39:40 +00:00
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