@@ -301,11 +301,17 @@ FOR_KNOWN_FOUNDATION_TYPES(CACHE_FOUNDATION_DECL)
301301 // / Structure that captures data that is segregated into different
302302 // / arenas.
303303 struct Arena {
304+ static_assert (alignof (TypeBase) >= 8 , " TypeBase not 8-byte aligned?" );
305+ static_assert (alignof (TypeBase) > static_cast <unsigned >(
306+ MetatypeRepresentation::Last_MetatypeRepresentation) + 1 ,
307+ " Use std::pair for MetatypeTypes and ExistentialMetatypeTypes." );
308+
304309 llvm::DenseMap<Type, ErrorType *> ErrorTypesWithOriginal;
305310 llvm::FoldingSet<TypeAliasType> TypeAliasTypes;
306311 llvm::FoldingSet<TupleType> TupleTypes;
307- llvm::DenseMap<std::pair<Type,char >, MetatypeType*> MetatypeTypes;
308- llvm::DenseMap<std::pair<Type,char >,
312+ llvm::DenseMap<llvm::PointerIntPair<TypeBase*, 3 , unsigned >,
313+ MetatypeType*> MetatypeTypes;
314+ llvm::DenseMap<llvm::PointerIntPair<TypeBase*, 3 , unsigned >,
309315 ExistentialMetatypeType*> ExistentialMetatypeTypes;
310316 llvm::DenseMap<Type, ArraySliceType*> ArraySliceTypes;
311317 llvm::DenseMap<std::pair<Type, Type>, DictionaryType *> DictionaryTypes;
@@ -3492,13 +3498,16 @@ MetatypeType *MetatypeType::get(Type T, Optional<MetatypeRepresentation> Repr,
34923498 auto properties = T->getRecursiveProperties ();
34933499 auto arena = getArena (properties);
34943500
3495- char reprKey;
3501+ unsigned reprKey;
34963502 if (Repr.hasValue ())
3497- reprKey = static_cast <char >(*Repr) + 1 ;
3503+ reprKey = static_cast <unsigned >(*Repr) + 1 ;
34983504 else
34993505 reprKey = 0 ;
35003506
3501- MetatypeType *&Entry = Ctx.getImpl ().getArena (arena).MetatypeTypes [{T, reprKey}];
3507+ auto pair = llvm::PointerIntPair<TypeBase*, 3 , unsigned >(T.getPointer (),
3508+ reprKey);
3509+
3510+ MetatypeType *&Entry = Ctx.getImpl ().getArena (arena).MetatypeTypes [pair];
35023511 if (Entry) return Entry;
35033512
35043513 return Entry = new (Ctx, arena) MetatypeType (
@@ -3517,13 +3526,16 @@ ExistentialMetatypeType::get(Type T, Optional<MetatypeRepresentation> repr,
35173526 auto properties = T->getRecursiveProperties ();
35183527 auto arena = getArena (properties);
35193528
3520- char reprKey;
3529+ unsigned reprKey;
35213530 if (repr.hasValue ())
3522- reprKey = static_cast <char >(*repr) + 1 ;
3531+ reprKey = static_cast <unsigned >(*repr) + 1 ;
35233532 else
35243533 reprKey = 0 ;
35253534
3526- auto &entry = ctx.getImpl ().getArena (arena).ExistentialMetatypeTypes [{T, reprKey}];
3535+ auto pair = llvm::PointerIntPair<TypeBase*, 3 , unsigned >(T.getPointer (),
3536+ reprKey);
3537+
3538+ auto &entry = ctx.getImpl ().getArena (arena).ExistentialMetatypeTypes [pair];
35273539 if (entry) return entry;
35283540
35293541 return entry = new (ctx, arena) ExistentialMetatypeType (
0 commit comments