@@ -136,33 +136,10 @@ void CodeGenFunction::GenerateOpenMPCapturedVars(
136
136
CapturedVars.push_back (Val);
137
137
} else if (CurCap->capturesThis ())
138
138
CapturedVars.push_back (CXXThisValue);
139
- else if (CurCap->capturesVariableByCopy ()) {
140
- llvm::Value *CV =
141
- EmitLoadOfLValue (EmitLValue (*I), SourceLocation ()).getScalarVal ();
142
-
143
- // If the field is not a pointer, we need to save the actual value
144
- // and load it as a void pointer.
145
- if (!CurField->getType ()->isAnyPointerType ()) {
146
- auto &Ctx = getContext ();
147
- auto DstAddr = CreateMemTemp (
148
- Ctx.getUIntPtrType (),
149
- Twine (CurCap->getCapturedVar ()->getName ()) + " .casted" );
150
- LValue DstLV = MakeAddrLValue (DstAddr, Ctx.getUIntPtrType ());
151
-
152
- auto *SrcAddrVal = EmitScalarConversion (
153
- DstAddr.getPointer (), Ctx.getPointerType (Ctx.getUIntPtrType ()),
154
- Ctx.getPointerType (CurField->getType ()), SourceLocation ());
155
- LValue SrcLV =
156
- MakeNaturalAlignAddrLValue (SrcAddrVal, CurField->getType ());
157
-
158
- // Store the value using the source type pointer.
159
- EmitStoreThroughLValue (RValue::get (CV), SrcLV);
160
-
161
- // Load the value using the destination type pointer.
162
- CV = EmitLoadOfLValue (DstLV, SourceLocation ()).getScalarVal ();
163
- }
164
- CapturedVars.push_back (CV);
165
- } else {
139
+ else if (CurCap->capturesVariableByCopy ())
140
+ CapturedVars.push_back (
141
+ EmitLoadOfLValue (EmitLValue (*I), SourceLocation ()).getScalarVal ());
142
+ else {
166
143
assert (CurCap->capturesVariable () && " Expected capture by reference." );
167
144
CapturedVars.push_back (EmitLValue (*I).getAddress ().getPointer ());
168
145
}
@@ -195,7 +172,8 @@ static Address castValueFromUintptr(CodeGenFunction &CGF, QualType DstType,
195
172
}
196
173
197
174
llvm::Function *
198
- CodeGenFunction::GenerateOpenMPCapturedStmtFunction (const CapturedStmt &S) {
175
+ CodeGenFunction::GenerateOpenMPCapturedStmtFunction (const CapturedStmt &S,
176
+ bool CastValToPtr) {
199
177
assert (
200
178
CapturedStmtInfo &&
201
179
" CapturedStmtInfo should be set when generating the captured function" );
@@ -219,9 +197,11 @@ CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S) {
219
197
// uintptr. This is necessary given that the runtime library is only able to
220
198
// deal with pointers. We can pass in the same way the VLA type sizes to the
221
199
// outlined function.
222
- if ((I->capturesVariableByCopy () && !ArgType->isAnyPointerType ()) ||
223
- I->capturesVariableArrayType ())
224
- ArgType = Ctx.getUIntPtrType ();
200
+ if (CastValToPtr) {
201
+ if ((I->capturesVariableByCopy () && !ArgType->isAnyPointerType ()) ||
202
+ I->capturesVariableArrayType ())
203
+ ArgType = Ctx.getUIntPtrType ();
204
+ }
225
205
226
206
if (I->capturesVariable () || I->capturesVariableByCopy ()) {
227
207
CapVar = I->getCapturedVar ();
@@ -275,9 +255,12 @@ CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S) {
275
255
AlignmentSource::Decl);
276
256
if (FD->hasCapturedVLAType ()) {
277
257
LValue CastedArgLVal =
278
- MakeAddrLValue (castValueFromUintptr (*this , FD->getType (),
279
- Args[Cnt]->getName (), ArgLVal),
280
- FD->getType (), AlignmentSource::Decl);
258
+ CastValToPtr
259
+ ? MakeAddrLValue (castValueFromUintptr (*this , FD->getType (),
260
+ Args[Cnt]->getName (),
261
+ ArgLVal),
262
+ FD->getType (), AlignmentSource::Decl)
263
+ : ArgLVal;
281
264
auto *ExprArg =
282
265
EmitLoadOfLValue (CastedArgLVal, SourceLocation ()).getScalarVal ();
283
266
auto VAT = FD->getCapturedVLAType ();
@@ -297,9 +280,16 @@ CodeGenFunction::GenerateOpenMPCapturedStmtFunction(const CapturedStmt &S) {
297
280
" Not expecting a captured pointer." );
298
281
auto *Var = I->getCapturedVar ();
299
282
QualType VarTy = Var->getType ();
300
- setAddrOfLocalVar (Var, castValueFromUintptr (*this , FD->getType (),
301
- Args[Cnt]->getName (), ArgLVal,
302
- VarTy->isReferenceType ()));
283
+ if (!CastValToPtr && VarTy->isReferenceType ()) {
284
+ Address Temp = CreateMemTemp (VarTy);
285
+ Builder.CreateStore (ArgLVal.getPointer (), Temp);
286
+ ArgLVal = MakeAddrLValue (Temp, VarTy);
287
+ }
288
+ setAddrOfLocalVar (Var, CastValToPtr ? castValueFromUintptr (
289
+ *this , FD->getType (),
290
+ Args[Cnt]->getName (), ArgLVal,
291
+ VarTy->isReferenceType ())
292
+ : ArgLVal.getAddress ());
303
293
} else {
304
294
// If 'this' is captured, load it into CXXThisValue.
305
295
assert (I->capturesThis ());
0 commit comments