@@ -217,8 +217,13 @@ static llvm::Value *bindMetadataAtIndex(IRGenFunction &IGF,
217
217
if (auto response = IGF.tryGetLocalTypeMetadata (elementArchetype, request))
218
218
return response.getMetadata ();
219
219
220
+ // If the pack is on the heap, the LSB is set, so mask it off.
220
221
patternPack =
221
- IGF.Builder .CreatePointerCast (patternPack, IGF.IGM .TypeMetadataPtrPtrTy );
222
+ IGF.Builder .CreatePtrToInt (patternPack, IGF.IGM .SizeTy );
223
+ patternPack =
224
+ IGF.Builder .CreateAnd (patternPack, llvm::ConstantInt::get (IGF.IGM .SizeTy , -2 ));
225
+ patternPack =
226
+ IGF.Builder .CreateIntToPtr (patternPack, IGF.IGM .TypeMetadataPtrPtrTy );
222
227
223
228
Address patternPackAddress (patternPack, IGF.IGM .TypeMetadataPtrTy ,
224
229
IGF.IGM .getPointerAlignment ());
@@ -245,8 +250,14 @@ static llvm::Value *bindWitnessTableAtIndex(IRGenFunction &IGF,
245
250
auto key = LocalTypeDataKind::forProtocolWitnessTable (conf);
246
251
if (auto *wtable = IGF.tryGetLocalTypeData (elementArchetype, key))
247
252
return wtable;
253
+
254
+ // If the pack is on the heap, the LSB is set, so mask it off.
255
+ wtablePack =
256
+ IGF.Builder .CreatePtrToInt (wtablePack, IGF.IGM .SizeTy );
257
+ wtablePack =
258
+ IGF.Builder .CreateAnd (wtablePack, llvm::ConstantInt::get (IGF.IGM .SizeTy , -2 ));
248
259
wtablePack =
249
- IGF.Builder .CreatePointerCast (wtablePack, IGF.IGM .WitnessTablePtrPtrTy );
260
+ IGF.Builder .CreateIntToPtr (wtablePack, IGF.IGM .WitnessTablePtrPtrTy );
250
261
251
262
Address patternPackAddress (wtablePack, IGF.IGM .WitnessTablePtrTy ,
252
263
IGF.IGM .getPointerAlignment ());
0 commit comments