mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-04 00:06:50 +00:00
bee782bb92
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
116 lines
4.3 KiB
C++
116 lines
4.3 KiB
C++
//===--- StmtCXX.cpp - Classes for representing C++ statements ------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the subclesses of Stmt class declared in StmtCXX.h
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/AST/StmtCXX.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
using namespace clang;
|
|
|
|
QualType CXXCatchStmt::getCaughtType() const {
|
|
if (ExceptionDecl)
|
|
return ExceptionDecl->getType();
|
|
return QualType();
|
|
}
|
|
|
|
CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc,
|
|
Stmt *tryBlock, ArrayRef<Stmt *> handlers) {
|
|
std::size_t Size = sizeof(CXXTryStmt);
|
|
Size += ((handlers.size() + 1) * sizeof(Stmt *));
|
|
|
|
void *Mem = C.Allocate(Size, alignof(CXXTryStmt));
|
|
return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers);
|
|
}
|
|
|
|
CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty,
|
|
unsigned numHandlers) {
|
|
std::size_t Size = sizeof(CXXTryStmt);
|
|
Size += ((numHandlers + 1) * sizeof(Stmt *));
|
|
|
|
void *Mem = C.Allocate(Size, alignof(CXXTryStmt));
|
|
return new (Mem) CXXTryStmt(Empty, numHandlers);
|
|
}
|
|
|
|
CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
|
|
ArrayRef<Stmt *> handlers)
|
|
: Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) {
|
|
Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1);
|
|
Stmts[0] = tryBlock;
|
|
std::copy(handlers.begin(), handlers.end(), Stmts + 1);
|
|
}
|
|
|
|
CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range,
|
|
DeclStmt *BeginStmt, DeclStmt *EndStmt,
|
|
Expr *Cond, Expr *Inc, DeclStmt *LoopVar,
|
|
Stmt *Body, SourceLocation FL,
|
|
SourceLocation CAL, SourceLocation CL,
|
|
SourceLocation RPL)
|
|
: Stmt(CXXForRangeStmtClass), ForLoc(FL), CoawaitLoc(CAL), ColonLoc(CL),
|
|
RParenLoc(RPL) {
|
|
SubExprs[RANGE] = Range;
|
|
SubExprs[BEGINSTMT] = BeginStmt;
|
|
SubExprs[ENDSTMT] = EndStmt;
|
|
SubExprs[COND] = Cond;
|
|
SubExprs[INC] = Inc;
|
|
SubExprs[LOOPVAR] = LoopVar;
|
|
SubExprs[BODY] = Body;
|
|
}
|
|
|
|
Expr *CXXForRangeStmt::getRangeInit() {
|
|
DeclStmt *RangeStmt = getRangeStmt();
|
|
VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl());
|
|
assert(RangeDecl && "for-range should have a single var decl");
|
|
return RangeDecl->getInit();
|
|
}
|
|
|
|
const Expr *CXXForRangeStmt::getRangeInit() const {
|
|
return const_cast<CXXForRangeStmt *>(this)->getRangeInit();
|
|
}
|
|
|
|
VarDecl *CXXForRangeStmt::getLoopVariable() {
|
|
Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
|
|
assert(LV && "No loop variable in CXXForRangeStmt");
|
|
return cast<VarDecl>(LV);
|
|
}
|
|
|
|
const VarDecl *CXXForRangeStmt::getLoopVariable() const {
|
|
return const_cast<CXXForRangeStmt *>(this)->getLoopVariable();
|
|
}
|
|
|
|
CoroutineBodyStmt *CoroutineBodyStmt::Create(
|
|
const ASTContext &C, CoroutineBodyStmt::CtorArgs const& Args) {
|
|
std::size_t Size = totalSizeToAlloc<Stmt *>(
|
|
CoroutineBodyStmt::FirstParamMove + Args.ParamMoves.size());
|
|
|
|
void *Mem = C.Allocate(Size, alignof(CoroutineBodyStmt));
|
|
return new (Mem) CoroutineBodyStmt(Args);
|
|
}
|
|
|
|
CoroutineBodyStmt::CoroutineBodyStmt(CoroutineBodyStmt::CtorArgs const &Args)
|
|
: Stmt(CoroutineBodyStmtClass), NumParams(Args.ParamMoves.size()) {
|
|
Stmt **SubStmts = getStoredStmts();
|
|
SubStmts[CoroutineBodyStmt::Body] = Args.Body;
|
|
SubStmts[CoroutineBodyStmt::Promise] = Args.Promise;
|
|
SubStmts[CoroutineBodyStmt::InitSuspend] = Args.InitialSuspend;
|
|
SubStmts[CoroutineBodyStmt::FinalSuspend] = Args.FinalSuspend;
|
|
SubStmts[CoroutineBodyStmt::OnException] = Args.OnException;
|
|
SubStmts[CoroutineBodyStmt::OnFallthrough] = Args.OnFallthrough;
|
|
SubStmts[CoroutineBodyStmt::Allocate] = Args.Allocate;
|
|
SubStmts[CoroutineBodyStmt::Deallocate] = Args.Deallocate;
|
|
SubStmts[CoroutineBodyStmt::ReturnValue] = Args.ReturnValue;
|
|
SubStmts[CoroutineBodyStmt::ReturnStmtOnAllocFailure] =
|
|
Args.ReturnStmtOnAllocFailure;
|
|
std::copy(Args.ParamMoves.begin(), Args.ParamMoves.end(),
|
|
const_cast<Stmt **>(getParamMoves().data()));
|
|
}
|