[PATCH] D43242: [Coroutines] PR34897: Fix incorrect elisions
Brian Gesiak via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 13 08:47:58 PST 2018
modocache created this revision.
modocache added reviewers: rsmith, GorNishanov, eric_niebler.
Herald added a subscriber: EricWF.
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, only elide allocations if the set of llvm.coro.destroy
instructions dominate all reachable terminator instructions in the function.
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. `check-llvm`
Repository:
rL LLVM
https://reviews.llvm.org/D43242
Files:
lib/Transforms/Coroutines/CoroElide.cpp
test/Transforms/Coroutines/coro-heap-elide.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43242.134051.patch
Type: text/x-patch
Size: 6026 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180213/aece478c/attachment.bin>
More information about the llvm-commits
mailing list