File tree Expand file tree Collapse file tree 5 files changed +26
-6
lines changed Expand file tree Collapse file tree 5 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -108,8 +108,12 @@ Function *ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
108
108
this ->LambdaCaptures [Cap.first ] = {
109
109
Offset, Cap.second ->getType ()->isReferenceType ()};
110
110
}
111
- if (LTC)
112
- this ->LambdaThisCapture = R->getField (LTC)->Offset ;
111
+ if (LTC) {
112
+ QualType CaptureType = R->getField (LTC)->Decl ->getType ();
113
+ this ->LambdaThisCapture = {R->getField (LTC)->Offset ,
114
+ CaptureType->isReferenceType () ||
115
+ CaptureType->isPointerType ()};
116
+ }
113
117
}
114
118
}
115
119
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ class ByteCodeEmitter {
62
62
// / Lambda captures.
63
63
llvm::DenseMap<const ValueDecl *, ParamOffset> LambdaCaptures;
64
64
// / Offset of the This parameter in a lambda record.
65
- unsigned LambdaThisCapture = 0 ;
65
+ ParamOffset LambdaThisCapture{ 0 , false } ;
66
66
// / Local descriptors.
67
67
llvm::SmallVector<SmallVector<Local, 8 >, 2 > Descriptors;
68
68
Original file line number Diff line number Diff line change @@ -2934,8 +2934,11 @@ bool ByteCodeExprGen<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {
2934
2934
if (DiscardResult)
2935
2935
return true ;
2936
2936
2937
- if (this ->LambdaThisCapture > 0 )
2938
- return this ->emitGetThisFieldPtr (this ->LambdaThisCapture , E);
2937
+ if (this ->LambdaThisCapture .Offset > 0 ) {
2938
+ if (this ->LambdaThisCapture .IsPtr )
2939
+ return this ->emitGetThisFieldPtr (this ->LambdaThisCapture .Offset , E);
2940
+ return this ->emitGetPtrThisField (this ->LambdaThisCapture .Offset , E);
2941
+ }
2939
2942
2940
2943
return this ->emitThis (E);
2941
2944
}
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ class EvalEmitter : public SourceMapper {
73
73
// / Lambda captures.
74
74
llvm::DenseMap<const ValueDecl *, ParamOffset> LambdaCaptures;
75
75
// / Offset of the This parameter in a lambda record.
76
- unsigned LambdaThisCapture = 0 ;
76
+ ParamOffset LambdaThisCapture{ 0 , false } ;
77
77
// / Local descriptors.
78
78
llvm::SmallVector<SmallVector<Local, 8 >, 2 > Descriptors;
79
79
Original file line number Diff line number Diff line change @@ -235,3 +235,16 @@ namespace LambdaToAPValue {
235
235
static_assert (g () == f (), " " );
236
236
}
237
237
}
238
+
239
+ namespace ns2_capture_this_byval {
240
+ struct S {
241
+ int s;
242
+ constexpr S (int s) : s{s} { }
243
+ constexpr auto f (S o) {
244
+ return [*this ,o] (auto a) { return s + o.s + a.s ; };
245
+ }
246
+ };
247
+
248
+ constexpr auto L = S{5 }.f(S{10 });
249
+ static_assert (L(S{100 }) == 115 , " " );
250
+ } // end test_captures_1::ns2_capture_this_byval
You can’t perform that action at this time.
0 commit comments