diff options
author | Eric Fiselier <eric@efcs.ca> | 2017-04-03 19:21:00 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2017-04-03 19:21:00 +0000 |
commit | bee782bb9212180689062b28d578981516655498 (patch) | |
tree | 9d73081b74a67048ea134a0b83a053aad7a6c16d /clang/lib/Sema/CoroutineStmtBuilder.h | |
parent | dee5565869e00ef1fa62ea25c2f04c7d54b9e9fd (diff) | |
download | bcm5719-llvm-bee782bb9212180689062b28d578981516655498.tar.gz bcm5719-llvm-bee782bb9212180689062b28d578981516655498.zip |
[coroutines] Fix rebuilding of implicit and dependent coroutine statements.
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
Diffstat (limited to 'clang/lib/Sema/CoroutineStmtBuilder.h')
-rw-r--r-- | clang/lib/Sema/CoroutineStmtBuilder.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/clang/lib/Sema/CoroutineStmtBuilder.h b/clang/lib/Sema/CoroutineStmtBuilder.h new file mode 100644 index 00000000000..4958576219e --- /dev/null +++ b/clang/lib/Sema/CoroutineStmtBuilder.h @@ -0,0 +1,70 @@ +//===- CoroutineStmtBuilder.h - Implicit coroutine stmt builder -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +//===----------------------------------------------------------------------===// +// +// This file defines CoroutineStmtBuilder, a class for building the implicit +// statements required for building a coroutine body. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_LIB_SEMA_COROUTINESTMTBUILDER_H +#define LLVM_CLANG_LIB_SEMA_COROUTINESTMTBUILDER_H + +#include "clang/AST/Decl.h" +#include "clang/AST/ExprCXX.h" +#include "clang/AST/StmtCXX.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Sema/SemaInternal.h" + +namespace clang { + +class CoroutineStmtBuilder : public CoroutineBodyStmt::CtorArgs { + Sema &S; + FunctionDecl &FD; + sema::FunctionScopeInfo &Fn; + bool IsValid = true; + SourceLocation Loc; + QualType RetType; + SmallVector<Stmt *, 4> ParamMovesVector; + const bool IsPromiseDependentType; + CXXRecordDecl *PromiseRecordDecl = nullptr; + +public: + /// \brief Construct a CoroutineStmtBuilder and initialize the promise + /// statement and initial/final suspends from the FunctionScopeInfo. + CoroutineStmtBuilder(Sema &S, FunctionDecl &FD, sema::FunctionScopeInfo &Fn, + Stmt *Body); + + /// \brief Build the coroutine body statements, including the + /// "promise dependent" statements when the promise type is not dependent. + bool buildStatements(); + + /// \brief Build the coroutine body statements that require a non-dependent + /// promise type in order to construct. + /// + /// For example different new/delete overloads are selected depending on + /// if the promise type provides `unhandled_exception()`, and therefore they + /// cannot be built until the promise type is complete so that we can perform + /// name lookup. + bool buildDependentStatements(); + + bool isInvalid() const { return !this->IsValid; } + +private: + bool makePromiseStmt(); + bool makeInitialAndFinalSuspend(); + bool makeNewAndDeleteExpr(); + bool makeOnFallthrough(); + bool makeOnException(); + bool makeReturnObject(); + bool makeReturnOnAllocFailure(); + bool makeParamMoves(); +}; + +} // end namespace clang + +#endif // LLVM_CLANG_LIB_SEMA_COROUTINESTMTBUILDER_H |