diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2012-03-01 04:01:32 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2012-03-01 04:01:32 +0000 |
commit | 23f0267e2d56c0407f12e62df3561ecf75d74e6e (patch) | |
tree | f6e536907913aaa1fa958f250092fefd74cb7d4c /include/clang | |
parent | 5e4e58b805e0e03a669aa517d1d20d4735a3192e (diff) |
Implement "optimization" for lambda-to-block conversion which inlines the generated block literal for lambdas which are immediately converted to block pointer type. This simplifies the AST, avoids an unnecessary copy of the lambda and makes it much easier to avoid copying the result onto the heap.
Note that this transformation has a substantial semantic effect outside of ARC: it gives the converted lambda lifetime semantics similar to a block literal. With ARC, the effect is much less obvious because the lifetime of blocks is already managed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151797 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/AST/Decl.h | 6 | ||||
-rw-r--r-- | include/clang/Sema/Sema.h | 7 |
2 files changed, 11 insertions, 2 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 1338657ff4..68fa374913 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -3060,6 +3060,7 @@ private: bool IsVariadic : 1; bool CapturesCXXThis : 1; bool BlockMissingReturnType : 1; + bool IsConversionFromLambda : 1; /// ParamInfo - new[]'d array of pointers to ParmVarDecls for the formal /// parameters of this function. This is null if a prototype or if there are /// no formals. @@ -3076,7 +3077,7 @@ protected: BlockDecl(DeclContext *DC, SourceLocation CaretLoc) : Decl(Block, DC, CaretLoc), DeclContext(Block), IsVariadic(false), CapturesCXXThis(false), - BlockMissingReturnType(true), + BlockMissingReturnType(true), IsConversionFromLambda(false), ParamInfo(0), NumParams(0), Body(0), SignatureAsWritten(0), Captures(0), NumCaptures(0) {} @@ -3138,6 +3139,9 @@ public: bool blockMissingReturnType() const { return BlockMissingReturnType; } void setBlockMissingReturnType(bool val) { BlockMissingReturnType = val; } + bool isConversionFromLambda() const { return IsConversionFromLambda; } + void setIsConversionFromLambda(bool val) { IsConversionFromLambda = val; } + bool capturesVariable(const VarDecl *var) const; void setCaptures(ASTContext &Context, diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 967dc29c4d..7d9f835000 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -3654,7 +3654,12 @@ public: /// block pointer conversion. void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, CXXConversionDecl *Conv); - + + ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, + SourceLocation ConvLocation, + CXXConversionDecl *Conv, + Expr *Src); + // ParseObjCStringLiteral - Parse Objective-C string literals. ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, Expr **Strings, |