From b40e4af8459c02b5dda2c6ad07aadfc5fe7719cf Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 5 Aug 2015 09:40:35 +0000 Subject: [PATCH] [AST] ArrayRefize BlockDecl::setCaptures. No functionality change intended. llvm-svn: 244027 --- clang/include/clang/AST/Decl.h | 8 +++----- clang/lib/AST/Decl.cpp | 23 +++++++---------------- clang/lib/Sema/SemaExpr.cpp | 3 +-- clang/lib/Sema/SemaLambda.cpp | 3 +-- clang/lib/Serialization/ASTReaderDecl.cpp | 3 +-- 5 files changed, 13 insertions(+), 27 deletions(-) diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 76fda1c09156..6a986ee9a0f0 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -3491,7 +3491,7 @@ private: Stmt *Body; TypeSourceInfo *SignatureAsWritten; - Capture *Captures; + const Capture *Captures; unsigned NumCaptures; unsigned ManglingNumber; @@ -3597,10 +3597,8 @@ public: bool capturesVariable(const VarDecl *var) const; - void setCaptures(ASTContext &Context, - const Capture *begin, - const Capture *end, - bool capturesCXXThis); + void setCaptures(ASTContext &Context, ArrayRef Captures, + bool CapturesCXXThis); unsigned getBlockManglingNumber() const { return ManglingNumber; diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 946d1bae21ef..486f2d6ab773 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -3757,26 +3757,17 @@ void BlockDecl::setParams(ArrayRef NewParamInfo) { } } -void BlockDecl::setCaptures(ASTContext &Context, - const Capture *begin, - const Capture *end, - bool capturesCXXThis) { - CapturesCXXThis = capturesCXXThis; +void BlockDecl::setCaptures(ASTContext &Context, ArrayRef Captures, + bool CapturesCXXThis) { + this->CapturesCXXThis = CapturesCXXThis; + this->NumCaptures = Captures.size(); - if (begin == end) { - NumCaptures = 0; - Captures = nullptr; + if (Captures.empty()) { + this->Captures = nullptr; return; } - NumCaptures = end - begin; - - // Avoid new Capture[] because we don't want to provide a default - // constructor. - size_t allocationSize = NumCaptures * sizeof(Capture); - void *buffer = Context.Allocate(allocationSize, /*alignment*/sizeof(void*)); - memcpy(buffer, begin, allocationSize); - Captures = static_cast(buffer); + this->Captures = Captures.copy(Context).data(); } bool BlockDecl::capturesVariable(const VarDecl *variable) const { diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index af4e4af5dfa5..dd99ad2f0c09 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -11397,8 +11397,7 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, Cap.isNested(), Cap.getInitExpr()); Captures.push_back(NewCap); } - BSI->TheDecl->setCaptures(Context, Captures.begin(), Captures.end(), - BSI->CXXThisCaptureIndex != 0); + BSI->TheDecl->setCaptures(Context, Captures, BSI->CXXThisCaptureIndex != 0); // If the user wrote a function type in some form, try to use that. if (!BSI->FunctionType.isNull()) { diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index 8220641166b2..952272e37f3f 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -1700,8 +1700,7 @@ ExprResult Sema::BuildBlockForLambdaConversion(SourceLocation CurrentLocation, SC_None); BlockDecl::Capture Capture(/*Variable=*/CapVar, /*ByRef=*/false, /*Nested=*/false, /*Copy=*/Init.get()); - Block->setCaptures(Context, &Capture, &Capture + 1, - /*CapturesCXXThis=*/false); + Block->setCaptures(Context, Capture, /*CapturesCXXThis=*/false); // Add a fake function body to the block. IR generation is responsible // for filling in the actual body, which cannot be expressed as an AST. diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 0242e7eed07f..06f7acaf7853 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -1304,8 +1304,7 @@ void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr)); } - BD->setCaptures(Reader.getContext(), captures.begin(), - captures.end(), capturesCXXThis); + BD->setCaptures(Reader.getContext(), captures, capturesCXXThis); } void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) {