@@ -358,6 +358,9 @@ Explosion irgen::emitConstantValue(IRGenModule &IGM, SILValue operand,
358358 } else if (auto *URCI = dyn_cast<UncheckedRefCastInst>(operand)) {
359359 return emitConstantValue (IGM, URCI->getOperand (), flatten);
360360
361+ } else if (auto *UCI = dyn_cast<UpcastInst>(operand)) {
362+ return emitConstantValue (IGM, UCI->getOperand (), flatten);
363+
361364 } else if (auto *T2TFI = dyn_cast<ThinToThickFunctionInst>(operand)) {
362365 SILType type = operand->getType ();
363366 auto *sTy = cast<llvm::StructType>(IGM.getTypeInfo (type).getStorageType ());
@@ -453,22 +456,37 @@ llvm::Constant *irgen::emitConstantObject(IRGenModule &IGM, ObjectInst *OI,
453456
454457 if (IGM.canMakeStaticObjectReadOnly (OI->getType ())) {
455458 if (!IGM.swiftImmortalRefCount ) {
456- auto *var = new llvm::GlobalVariable (IGM.Module , IGM.Int8Ty ,
457- /* constant*/ true , llvm::GlobalValue::ExternalLinkage,
458- /* initializer*/ nullptr , " _swiftImmortalRefCount" );
459- IGM.swiftImmortalRefCount = var;
459+ if (IGM.Context .LangOpts .hasFeature (Feature::Embedded)) {
460+ // = HeapObject.immortalRefCount
461+ IGM.swiftImmortalRefCount = llvm::ConstantInt::get (IGM.IntPtrTy , -1 );
462+ } else {
463+ IGM.swiftImmortalRefCount = llvm::ConstantExpr::getPtrToInt (
464+ new llvm::GlobalVariable (IGM.Module , IGM.Int8Ty ,
465+ /* constant*/ true , llvm::GlobalValue::ExternalLinkage,
466+ /* initializer*/ nullptr , " _swiftImmortalRefCount" ),
467+ IGM.IntPtrTy );
468+ }
460469 }
461470 if (!IGM.swiftStaticArrayMetadata ) {
462471 auto *classDecl = IGM.getStaticArrayStorageDecl ();
463472 assert (classDecl && " no __StaticArrayStorage in stdlib" );
464473 CanType classTy = CanType (ClassType::get (classDecl, Type (), IGM.Context ));
465- LinkEntity entity = LinkEntity::forTypeMetadata (classTy, TypeMetadataAddress::AddressPoint);
466- auto *metatype = IGM.getAddrOfLLVMVariable (entity, NotForDefinition, DebugTypeInfo ());
467- IGM.swiftStaticArrayMetadata = cast<llvm::GlobalVariable>(metatype);
474+ if (IGM.Context .LangOpts .hasFeature (Feature::Embedded)) {
475+ LinkEntity entity = LinkEntity::forTypeMetadata (classTy, TypeMetadataAddress::AddressPoint,
476+ /* forceShared=*/ true );
477+ // In embedded swift, the metadata for the array buffer class only needs to be very minimal:
478+ // No vtable needed, because the object is never destructed. It only contains the null super-
479+ // class pointer.
480+ llvm::Constant *superClass = llvm::ConstantPointerNull::get (IGM.Int8PtrTy );
481+ IGM.swiftStaticArrayMetadata = IGM.getAddrOfLLVMVariable (entity, superClass, DebugTypeInfo ());
482+ } else {
483+ LinkEntity entity = LinkEntity::forTypeMetadata (classTy, TypeMetadataAddress::AddressPoint);
484+ IGM.swiftStaticArrayMetadata = IGM.getAddrOfLLVMVariable (entity, NotForDefinition, DebugTypeInfo ());
485+ }
468486 }
469487 elements[0 ].add (llvm::ConstantStruct::get (ObjectHeaderTy, {
470488 IGM.swiftStaticArrayMetadata ,
471- llvm::ConstantExpr::getPtrToInt ( IGM.swiftImmortalRefCount , IGM. IntPtrTy ) }));
489+ IGM.swiftImmortalRefCount }));
472490 } else {
473491 elements[0 ].add (llvm::Constant::getNullValue (ObjectHeaderTy));
474492 }
0 commit comments