Skip to content

Commit 78d11de

Browse files
committed
IRGen: Emit fixed type descriptors for structs and enums with @_alignment attributes
This attribute is used in the simd overlay. To ensure we can layout SIMD types correctly, emit a fixed type descriptor instead of a field type descriptor for these types.
1 parent 527482c commit 78d11de

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

lib/IRGen/GenEnum.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5684,6 +5684,12 @@ const TypeInfo *TypeConverter::convertEnumType(TypeBase *key, CanType type,
56845684
void IRGenModule::emitEnumDecl(EnumDecl *theEnum) {
56855685
emitEnumMetadata(*this, theEnum);
56865686
emitNestedTypeDecls(theEnum->getMembers());
5687+
5688+
if (shouldEmitOpaqueTypeMetadataRecord(theEnum)) {
5689+
emitOpaqueTypeMetadataRecord(theEnum);
5690+
return;
5691+
}
5692+
56875693
emitFieldMetadataRecord(theEnum);
56885694
}
56895695

lib/IRGen/GenReflection.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,17 @@ void IRGenModule::emitOpaqueTypeMetadataRecord(const NominalTypeDecl *nominalDec
557557
builder.emit();
558558
}
559559

560+
bool IRGenModule::shouldEmitOpaqueTypeMetadataRecord(
561+
const NominalTypeDecl *nominalDecl) {
562+
if (nominalDecl->getAttrs().hasAttribute<AlignmentAttr>()) {
563+
auto &ti = getTypeInfoForUnlowered(nominalDecl->getDeclaredTypeInContext());
564+
if (isa<FixedTypeInfo>(ti))
565+
return true;
566+
}
567+
568+
return false;
569+
}
570+
560571
/// Builds a constant LLVM struct describing the layout of a fixed-size
561572
/// SIL @box. These look like closure contexts, but without any necessary
562573
/// bindings or metadata sources, and only a single captured value.

lib/IRGen/GenStruct.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,12 @@ unsigned irgen::getPhysicalStructFieldIndex(IRGenModule &IGM, SILType baseType,
839839
void IRGenModule::emitStructDecl(StructDecl *st) {
840840
emitStructMetadata(*this, st);
841841
emitNestedTypeDecls(st->getMembers());
842+
843+
if (shouldEmitOpaqueTypeMetadataRecord(st)) {
844+
emitOpaqueTypeMetadataRecord(st);
845+
return;
846+
}
847+
842848
emitFieldMetadataRecord(st);
843849
}
844850

lib/IRGen/IRGenModule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,10 @@ class IRGenModule {
771771
/// from this module.
772772
void emitOpaqueTypeMetadataRecord(const NominalTypeDecl *nominalDecl);
773773

774+
/// Some nominal type declarations require us to emit a fixed-size type
775+
/// descriptor, because they have special layout considerations.
776+
bool shouldEmitOpaqueTypeMetadataRecord(const NominalTypeDecl *nominalDecl);
777+
774778
/// Emit reflection metadata records for builtin and imported types referenced
775779
/// from this module.
776780
void emitBuiltinReflectionMetadata();

0 commit comments

Comments
 (0)