@@ -4299,11 +4299,12 @@ static void emitDirectForeignParameter(IRGenFunction &IGF, Explosion &in,
4299
4299
// The ABI IR types for the entrypoint might differ from the
4300
4300
// Swift IR types for the body of the function.
4301
4301
4302
+ bool IsDirectFlattened = AI.isDirect () && AI.getCanBeFlattened ();
4303
+
4302
4304
llvm::Type *coercionTy = AI.getCoerceToType ();
4303
4305
4304
4306
ArrayRef<llvm::Type*> expandedTys;
4305
- if (AI.isDirect () && AI.getCanBeFlattened () &&
4306
- isa<llvm::StructType>(coercionTy)) {
4307
+ if (IsDirectFlattened && isa<llvm::StructType>(coercionTy)) {
4307
4308
const auto *ST = cast<llvm::StructType>(coercionTy);
4308
4309
expandedTys = llvm::ArrayRef (ST->element_begin (), ST->getNumElements ());
4309
4310
} else if (coercionTy == paramTI.getStorageType ()) {
@@ -4344,7 +4345,8 @@ static void emitDirectForeignParameter(IRGenFunction &IGF, Explosion &in,
4344
4345
Address coercedAddr = IGF.Builder .CreateElementBitCast (temporary, coercionTy);
4345
4346
4346
4347
// Break down a struct expansion if necessary.
4347
- if (auto expansionTy = dyn_cast<llvm::StructType>(coercionTy)) {
4348
+ if (IsDirectFlattened && isa<llvm::StructType>(coercionTy)) {
4349
+ auto expansionTy = cast<llvm::StructType>(coercionTy);
4348
4350
auto layout = IGF.IGM .DataLayout .getStructLayout (expansionTy);
4349
4351
for (unsigned i = 0 , e = expansionTy->getNumElements (); i != e; ++i) {
4350
4352
auto fieldOffset = Size (layout->getElementOffset (i));
0 commit comments