summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaCoroutine.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [coroutines] Make sure auto return type of await_resume is properly handledGor Nishanov2017-09-051-2/+2
| | | | | | | | | | | | Reviewers: rsmith, EricWF Reviewed By: rsmith Subscribers: javed.absar, cfe-commits Differential Revision: https://reviews.llvm.org/D37454 llvm-svn: 312565
* [coroutines] Support coroutine-handle returning await-suspend (i.e symmetric ↵Gor Nishanov2017-08-251-10/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | control transfer) Summary: If await_suspend returns a coroutine_handle, as in the example below: ``` coroutine_handle<> await_suspend(coroutine_handle<> h) { coro.promise().waiter = h; return coro; } ``` suspensionExpression processing will resume the coroutine pointed at by that handle. Related LLVM change rL311751 makes resume calls of this kind `musttail` at any optimization level. This enables unlimited symmetric control transfer from coroutine to coroutine without blowing up the stack. Reviewers: GorNishanov Reviewed By: GorNishanov Subscribers: rsmith, EricWF, cfe-commits Differential Revision: https://reviews.llvm.org/D37131 llvm-svn: 311762
* Remove incorrect FIXME comment; the FIXME was addressed before the changes ↵Eric Fiselier2017-07-101-2/+0
| | | | | | were committed llvm-svn: 307515
* Remove non-ascii characters introduced in r307513Eric Fiselier2017-07-101-4/+4
| | | | llvm-svn: 307514
* [coroutines] Include the implicit object parameter type when looking up ↵Eric Fiselier2017-07-101-15/+39
| | | | | | | | | coroutine_traits for member functions. This patch was originally from Toby Allsopp, but I hijacked it and fixed it up with his permission. llvm-svn: 307513
* [coroutines] Fix co_await for range statementEric Fiselier2017-06-141-17/+18
| | | | | | | | | | | | | | | | | Summary: Currently we build the co_await expressions on the wrong implicit statements of the implicit ranged for; Specifically we build the co_await expression wrapping the range declaration, but it should wrap the begin expression. This patch fixes co_await on range for. Reviewers: rsmith, GorNishanov Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D34021 llvm-svn: 305363
* [coroutines] Fix rebuilding of dependent coroutine parametersEric Fiselier2017-06-031-9/+10
| | | | | | | | | | | | | | | | Summary: We were not handling correctly rebuilding of parameter and were not creating copies for them. Now we will always rebuild parameter moves in TreeTransform's TransformCoroutineBodyStmt. Reviewers: rsmith, GorNishanov Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33797 llvm-svn: 304620
* [coroutines] Fix checking for prvalue-ness of `await_suspend` return typeEric Fiselier2017-05-311-2/+5
| | | | | | | | | | | | | | | | | Summary: @rsmith Does this correctly address the issues mentioned in https://reviews.llvm.org/D33625#inline-292971 ? Reviewers: rsmith, EricWF Reviewed By: EricWF Subscribers: cfe-commits, rsmith Differential Revision: https://reviews.llvm.org/D33636 llvm-svn: 304373
* [coroutines] Fix assertion during -Wuninitialized analysisEric Fiselier2017-05-311-0/+1
| | | | | | | | | | | | | | Summary: @rsmith Is there a better place to put this test? Reviewers: GorNishanov, rsmith Reviewed By: GorNishanov Subscribers: cfe-commits, rsmith Differential Revision: https://reviews.llvm.org/D33660 llvm-svn: 304331
* [coroutines] Diagnose invalid result types for `await_resume` and ↵Eric Fiselier2017-05-281-0/+35
| | | | | | | | | | | | | | | | | | | | | | `await_suspend` and add missing conversions. Summary: The expression `await_ready` is required to be contextually convertible to bool and `await_suspend` must be a prvalue of either `void` or `bool`. This patch adds diagnostics for when those requirements are violated. It also correctly performs the contextual conversion to bool on the result of `await_ready` Reviewers: GorNishanov, rsmith Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33625 llvm-svn: 304094
* [coroutines] Diagnose when promise types fail to declare either return_void ↵Eric Fiselier2017-05-251-11/+37
| | | | | | | | | | | | | | | | | | | or return_value. Summary: According to the PDTS it's perfectly legal to have a promise type that defines neither `return_value` nor `return_void`. However a coroutine that uses such a promise type will almost always have UB, because it can never `co_return`. This patch changes Clang to diagnose such cases as an error. It also cleans up some of the diagnostic messages relating to member lookup in the promise type. Reviewers: GorNishanov, rsmith Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33534 llvm-svn: 303868
* [coroutines] Fix fallthrough diagnostics for coroutinesEric Fiselier2017-05-251-2/+5
| | | | | | | | | | | | | | | | | | | | Summary: This patch fixes a number of issues with the analysis warnings emitted when a coroutine may reach the end of the function w/o returning. * Fix bug where coroutines with `return_value` are incorrectly diagnosed as missing `co_return`'s. * Rework diagnostic message to no longer say "non-void coroutine", because that implies the coroutine doesn't have a void return type, which it might. In this case a non-void coroutine is one who's promise type does not contain `return_void()` As a side-effect of this patch, coroutine bodies that contain an invalid coroutine promise objects are marked as invalid. Reviewers: GorNishanov, rsmith, aaron.ballman, majnemer Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33532 llvm-svn: 303831
* [coroutines] Add support for coroutines with non-scalar parametersGor Nishanov2017-05-241-1/+61
| | | | | | | | | | | | | | Summary: Simple types like int are handled by LLVM Coroutines just fine. But for non-scalar parameters we need to create copies of those parameters in the coroutine frame and make all uses of those parameters to refer to parameter copies. Reviewers: rsmith, EricWF, GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33507 llvm-svn: 303803
* [coroutines] Improved diagnostics when unhandled_exception is missing in the ↵Gor Nishanov2017-05-241-4/+4
| | | | | | | | | | | | | | | | promise_type Summary: Now we helpfully provide a note pointing at the promise_type in question. Reviewers: EricWF, GorNishanov Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33481 llvm-svn: 303752
* [coroutines] Wrap the body of the coroutine in try-catchGor Nishanov2017-05-221-0/+9
| | | | | | | | | | | | | | | | | | | | | | Summary: If unhandled_exception member function is present in the coroutine promise, wrap the body of the coroutine in: ``` try { body } catch(...) { promise.unhandled_exception(); } ``` Reviewers: EricWF, rnk, rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31692 llvm-svn: 303583
* [coroutines] Build GRO declaration and return GRO statementGor Nishanov2017-05-221-19/+99
| | | | | | | | | | | | | | | | | | Summary: 1. build declaration of the gro local variable that keeps the result of get_return_object. 2. build return statement returning the gro variable 3. emit them during CodeGen 4. sema and CodeGen tests updated Reviewers: EricWF, rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31646 llvm-svn: 303573
* Assert that a valid operator new/delete signature is always found by the ↵Eric Fiselier2017-04-181-4/+3
| | | | | | coroutine body llvm-svn: 300529
* Speculatively attempt to fix bot failures caused by recent coroutine changes.Eric Fiselier2017-04-181-3/+6
| | | | llvm-svn: 300528
* [coroutines] Fix building of new/delete expressions when ↵Eric Fiselier2017-04-181-8/+75
| | | | | | | | | | | | | | | | | | | | | | get_return_object_on_allocation_failure() is present. Summary: This patch implements [dcl.fct.def.coroutine]p8: > The unqualified-id get_return_object_on_allocation_failure is looked up in the scope of > class P by class member access lookup (3.4.5). If a declaration is found, ..., and if a > global allocation function is selected, the ::operator new(size_t, nothrow_t) form shall be used. > [...] > The allocation function used in this case must have a non-throwing noexcept-specification. Reviewers: GorNishanov, rsmith, majnemer, aaron.ballman Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31562 llvm-svn: 300524
* Revert r300504 - [coroutines] Fix rebuilding of implicit and dependent ↵Eric Fiselier2017-04-171-75/+8
| | | | | | | | | coroutine statements. I have no idea what's happening here. The tests that fail on all of the bots pass on my machine. Further investigation needed. llvm-svn: 300511
* [coroutines] Fix rebuilding of implicit and dependent coroutine statements.Eric Fiselier2017-04-171-8/+75
| | | | | | | | | | | | | | | | | | | Summary: Certain implicitly generated coroutine statements, such as the calls to 'return_value()' or `return_void()` or `get_return_object_on_allocation_failure()`, cannot be built until the promise type is no longer dependent. This means they are not built until after the coroutine body statement has been transformed. This patch fixes an issue where these statements would never be built for coroutine templates. It also fixes a small issue where diagnostics about `get_return_object_on_allocation_failure()` were incorrectly suppressed. Reviewers: rsmith, majnemer, GorNishanov, aaron.ballman Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31487 llvm-svn: 300504
* Revert r300420 - [coroutines] Fix building of new/delete expressions when ↵Eric Fiselier2017-04-161-75/+8
| | | | | | get_return_object_on_allocation_failure() is present llvm-svn: 300421
* [coroutines] Fix building of new/delete expressions when ↵Eric Fiselier2017-04-161-8/+75
| | | | | | | | | | | | | | | | | | | | | | get_return_object_on_allocation_failure() is present. Summary: This patch implements [dcl.fct.def.coroutine]p8: > The unqualified-id get_return_object_on_allocation_failure is looked up in the scope of > class P by class member access lookup (3.4.5). If a declaration is found, ..., and if a > global allocation function is selected, the ::operator new(size_t, nothrow_t) form shall be used. > [...] > The allocation function used in this case must have a non-throwing noexcept-specification. Reviewers: GorNishanov, rsmith, majnemer, aaron.ballman Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31562 llvm-svn: 300420
* [coroutines] Fix rebuilding of implicit and dependent coroutine statements.Eric Fiselier2017-04-031-67/+61
| | | | | | | | | | | | | | | | | | | Summary: Certain implicitly generated coroutine statements, such as the calls to 'return_value()' or `return_void()` or `get_return_object_on_allocation_failure()`, cannot be built until the promise type is no longer dependent. This means they are not built until after the coroutine body statement has been transformed. This patch fixes an issue where these statements would never be built for coroutine templates. It also fixes a small issue where diagnostics about `get_return_object_on_allocation_failure()` were incorrectly suppressed. Reviewers: rsmith, majnemer, GorNishanov, aaron.ballman Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31487 llvm-svn: 299380
* Use BuildReturnStmt in SemaCoroutine to unbreak sanitizer tests.Gor Nishanov2017-03-281-2/+7
| | | | | | | | FIXME: ActOnReturnStmt expects a scope that is inside of the function, due to CheckJumpOutOfSEHFinally(*this, ReturnLoc, *CurScope->getFnParent()); S.getCurScope()->getFnParent() == nullptr at ActOnFinishFunctionBody when CoroutineBodyStmt is built. Figure it out and fix it. llvm-svn: 298893
* [coroutines] Handle get_return_object_on_allocation_failureGor Nishanov2017-03-271-3/+65
| | | | | | | | | | | | | | | | | Summary: If promise_type has get_return_object_on_allocation_failure defined, check if an allocation function returns nullptr, and if so, return the result of get_return_object_on_allocation_failure(). Reviewers: rsmith, EricWF Reviewed By: EricWF Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D31399 llvm-svn: 298891
* [coroutines] Implement unhandled_exception changes.Eric Fiselier2017-03-231-49/+19
| | | | | | | | | | | | | | | | | | Summary: This patch adopts the recent changes that renamed `set_exception(exception_pointer)` to `unhandled_exception()`. Additionally `unhandled_exception()` is now required, and so an error is emitted when exceptions are enabled but the promise type does not provide the member. When exceptions are disabled a warning is emitted instead of an error, The warning notes that the `unhandled_exception()` function is required when exceptions are enabled. Reviewers: rsmith, GorNishanov, aaron.ballman, majnemer Reviewed By: GorNishanov Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D30859 llvm-svn: 298565
* [coroutines] Fix diagnostics depending on the first coroutine statement.Eric Fiselier2017-03-111-21/+14
| | | | | | | | | | | | | | | | | | Summary: Some coroutine diagnostics need to point to the location of the first coroutine keyword in the function, like when diagnosing a `return` inside a coroutine. Previously we did this by storing each *valid* coroutine statement in a list and select the first one to use in diagnostics. However if every coroutine statement is invalid we would have no location to point to. This patch fixes the storage of the first coroutine statement location, ensuring that it gets stored even when the resulting AST node would be invalid. This patch also removes the `CoroutineStmts` list in `FunctionScopeInfo` because it was unused. Reviewers: rsmith, GorNishanov, aaron.ballman Reviewed By: GorNishanov Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D30776 llvm-svn: 297547
* [coroutines] Refactor SuspendExpr to create just one OpaqueValue (almost NFC)Gor Nishanov2017-03-111-8/+10
| | | | | | | | | | | | | | | | Summary: Create only one OpaqueValue for await_ready/await_suspend/await_resume. Store OpaqueValue used in the CoroutineSuspendExpr node, so that CodeGen does not have to hunt looking for it. Reviewers: rsmith, EricWF, aaron.ballman Reviewed By: EricWF Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D30775 llvm-svn: 297541
* [coroutines] Build and pass coroutine_handle to await_suspendGor Nishanov2017-03-091-13/+109
| | | | | | | | | | | | | | | | Summary: This patch adds passing a coroutine_handle object to await_suspend calls. It builds the coroutine_handle using coroutine_handle<PromiseType>::from_address(__builtin_coro_frame()). (a revision of https://reviews.llvm.org/D26316 that for some reason refuses to apply via arc patch) Reviewers: GorNishanov Subscribers: mehdi_amini, cfe-commits, EricWF Differential Revision: https://reviews.llvm.org/D30769 llvm-svn: 297356
* Fix unused variable in SemaCoroutine.cppEric Fiselier2017-03-071-1/+0
| | | | llvm-svn: 297105
* [coroutines] Add DependentCoawaitExpr and fix re-building CoroutineBodyStmt.Eric Fiselier2017-03-061-212/+321
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: The changes contained in this patch are: 1. Defines a new AST node `CoawaitDependentExpr` for representing co_await expressions while the promise type is still dependent. 2. Correctly detect and transform the 'co_await' operand to `p.await_transform(<expr>)` when possible. 3. Change the initial/final suspend points to build during the initial parse, so they have the correct operator co_await lookup results. 4. Fix transformation of the CoroutineBodyStmt so that it doesn't re-build the final/initial suspends. @rsmith: This change is a little big, but it's not trivial for me to split it up. Please let me know if you would prefer this submitted as multiple patches. Reviewers: rsmith, GorNishanov Reviewed By: rsmith Subscribers: ABataev, rsmith, mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D26057 llvm-svn: 297093
* [coroutines] Improve diagnostics when building implicit constructs.Eric Fiselier2017-03-061-19/+27
| | | | | | | | | | Previously when a coroutine was building the implicit setup/destroy constructs it would emit diagostics about failures on the first co_await/co_return/co_yield it encountered. This was confusing because that construct may not itself be ill-formed. This patch moves the diagnostics to the function start instead. llvm-svn: 297089
* [coroutines] NFC: Refactor Sema::CoroutineBodyStmt construction.Gor Nishanov2017-02-131-78/+159
| | | | | | | | | | | | | | | | | | | Summary: Sema::CheckCompletedCoroutineBody was growing unwieldy with building all of the substatements. Also, constructors for CoroutineBodyStmt had way too many parameters. Instead, CoroutineBodyStmt now defines CtorArgs structure with all of the required construction parameters. CheckCompleteCoroutineBody delegates construction of individual substatements to short functions one per each substatement. Also, added a drive-by fix of initializing CoroutinePromise to nullptr in ScopeInfo.h. And addressed the FIXME that wanted to tail allocate extra room at the end of the CoroutineBodyStmt to hold parameter move expressions. (The comment was longer that the code that implemented tail allocation). Reviewers: rsmith, EricWF Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D28835 llvm-svn: 294933
* Remove redundant passing around of a "ContainsAutoType" flag.Richard Smith2017-01-121-1/+1
| | | | | | | | | | | | This flag serves no purpose other than to prevent us walking through a type to check whether it contains an 'auto' specifier; this duplication of information is error-prone, does not appear to provide any performance benefit, and will become less practical once we support C++1z deduced class template types and eventually constrained types from the Concepts TS. No functionality change intended. llvm-svn: 291737
* [coroutines] Sema: Allow co_return all by itself.Gor Nishanov2017-01-101-11/+0
| | | | | | | | | | Reviewers: rsmith, EricWF Subscribers: mehdi_amini, llvm-commits, EricWF Differential Revision: https://reviews.llvm.org/D26038 llvm-svn: 291513
* [coroutines] Add diagnostics for copy/move assignment operators and ↵Eric Fiselier2016-10-271-47/+78
| | | | | | | | | | | | | | functions with deduced return types. Summary: The title says it all. Additionally this patch refactors the diagnostic code into a separate function. Reviewers: GorNishanov, rsmith Subscribers: majnemer, mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D25292 llvm-svn: 285331
* [coroutines] Add allocation and deallocation substatements.Gor Nishanov2016-10-271-11/+144
| | | | | | | | | | | | | | Summary: SemaCoroutine: Add allocation / deallocation substatements. CGCoroutine/Test: Emit allocation and deallocation + test. Reviewers: rsmith Subscribers: ABataev, EricWF, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D25879 llvm-svn: 285306
* [coroutines] Build fallthrough and set_exception statements.Eric Fiselier2016-10-271-5/+81
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds semantic checking and building of the fall-through `co_return;` statement as well as the `p.set_exception(std::current_exception())` call for handling uncaught exceptions. The fall-through statement is built and checked according to: > [dcl.fct.def.coroutine]/4 > The unqualified-ids return_void and return_value are looked up in the scope of class P. If > both are found, the program is ill-formed. If the unqualified-id return_void is found, flowing > off the end of a coroutine is equivalent to a co_return with no operand. Otherwise, flowing off > the end of a coroutine results in undefined behavior. Similarly the `set_exception` call is only built when that unqualified-id is found in the scope of class P. Additionally this patch adds fall-through warnings for non-void returning coroutines. Since it's surprising undefined behavior I thought it would be important to add the warning right away. Reviewers: majnemer, GorNishanov, rsmith Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D25349 llvm-svn: 285271
* [coroutines] Fix co_return statement for initializer list argumentsEric Fiselier2016-10-061-1/+1
| | | | | | | | | | | | | | | Summary: Previously the statement `co_return {42}` would be transformed into `P.return_void()`, since the type of `{42}` is represented as `void` by Clang. This patch fixes the bug by checking for `InitListExpr` arguments and transforming them accordingly. Reviewers: majnemer, GorNishanov, rsmith Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D25296 llvm-svn: 283495
* [coroutines] Switch to using std::experimental namespace per P0057R5Gor Nishanov2016-10-041-4/+5
| | | | | | | | | | | | | | Summary: Look for coroutine_traits and friends in std::experimental namespace. Patch (mostly) by EricWF. Reviewers: cfe-commits, EricWF, rsmith Subscribers: majnemer, mehdi_amini Differential Revision: https://reviews.llvm.org/D25068 llvm-svn: 283170
* [coroutines] Diagnose when 'main' is declared as a coroutine.Eric Fiselier2016-09-301-0/+5
| | | | | | | | | | | | Summary: The title says it all. Reviewers: rsmith, GorNishanov Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D25078 llvm-svn: 282973
* [Coroutines] Fix assertion about uncorrected typos in ↵Eric Fiselier2016-09-291-1/+14
| | | | | | co_await/co_yield/co_return expressions llvm-svn: 282792
* Re-commit "[Temporary] Add an ExprWithCleanups for each C++ ↵Tim Shen2016-06-211-2/+2
| | | | | | | | | | MaterializeTemporaryExpr." Since D21243 fixes relative clang-tidy tests. This reverts commit a71d9fbd41e99def9159af2b01ef6509394eaeed. llvm-svn: 273312
* Revert "[Temporary] Add an ExprWithCleanups for each C++ ↵Tim Shen2016-06-091-2/+2
| | | | | | | | | MaterializeTemporaryExpr." This reverts r272296, since there are clang-tidy failures that appear to be caused by this change. llvm-svn: 272310
* [Temporary] Add an ExprWithCleanups for each C++ MaterializeTemporaryExpr.Tim Shen2016-06-091-2/+2
| | | | | | | | | | | These ExprWithCleanups are added for holding a RunCleanupsScope not for destructor calls; rather, they are for lifetime marks. This requires ExprWithCleanups to keep a bit to indicate whether it have cleanups with side effects (e.g. dtor calls). Differential Revision: http://reviews.llvm.org/D20498 llvm-svn: 272296
* [coroutines] Build a CoroutineBodyStmt when finishing parsing a coroutine, ↵Richard Smith2015-11-241-4/+65
| | | | | | and form the initial_suspend, final_suspend, and get_return_object calls. llvm-svn: 253946
* [coroutines] Check for overload sets in co_yield / co_return operands being ↵Richard Smith2015-11-221-11/+8
| | | | | | resolved by a call to yield_value / return_value before rejecting them. llvm-svn: 253817
* [coroutines] Build implicit return_value / return_void calls for co_return.Richard Smith2015-11-221-6/+22
| | | | llvm-svn: 253816
* [coroutines] Materialize the awaitable before generating the await_* calls.Richard Smith2015-11-221-5/+9
| | | | llvm-svn: 253812
OpenPOWER on IntegriCloud