Skip to content

Commit 3408078

Browse files
committed
[IRGen] Fix layout string generation for pre-specialized metadata
rdar://108012057 Pre-specialized metadata has to be specifically handled by using the bound generic type instead of the unbound one. All the necessary information is already being passed down as BoundGenericTypeCharacteristics, we just need to apply them when present.
1 parent 2f3a946 commit 3408078

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4465,6 +4465,7 @@ namespace {
44654465

44664466
protected:
44674467
using super::asImpl;
4468+
using super::B;
44684469
using super::getLoweredType;
44694470
using super::IGM;
44704471
using super::Target;
@@ -4488,6 +4489,48 @@ namespace {
44884489

44894490
SILType getLoweredType() { return SILType::getPrimitiveObjectType(type); }
44904491

4492+
llvm::Constant *emitLayoutString() {
4493+
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses))
4494+
return nullptr;
4495+
auto lowered = getLoweredType();
4496+
auto &ti = IGM.getTypeInfo(lowered);
4497+
auto *typeLayoutEntry =
4498+
ti.buildTypeLayoutEntry(IGM, lowered, /*useStructLayouts*/ true);
4499+
auto genericSig =
4500+
lowered.getNominalOrBoundGenericNominal()->getGenericSignature();
4501+
4502+
return typeLayoutEntry->layoutString(IGM, genericSig);
4503+
}
4504+
4505+
llvm::Constant *getLayoutString() {
4506+
return emitLayoutString();
4507+
}
4508+
4509+
void addLayoutStringPointer() {
4510+
if (auto *layoutString = getLayoutString()) {
4511+
B.addSignedPointer(layoutString,
4512+
IGM.getOptions().PointerAuth.TypeLayoutString,
4513+
PointerAuthEntity::Special::TypeLayoutString);
4514+
} else {
4515+
B.addNullPointer(IGM.Int8PtrTy);
4516+
}
4517+
}
4518+
4519+
bool hasLayoutString() {
4520+
if (!IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses)) {
4521+
return false;
4522+
}
4523+
4524+
return !!getLayoutString();
4525+
}
4526+
4527+
llvm::Constant *emitNominalTypeDescriptor() {
4528+
auto descriptor =
4529+
StructContextDescriptorBuilder(IGM, Target, RequireMetadata,
4530+
hasLayoutString()).emit();
4531+
return descriptor;
4532+
}
4533+
44914534
ConstantReference emitValueWitnessTable(bool relativeReference) {
44924535
return irgen::emitValueWitnessTable(IGM, type, false, relativeReference);
44934536
}

lib/IRGen/GenValueWitness.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -989,9 +989,10 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
989989
return addFunction(getDestroyStrongFunction(IGM));
990990
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
991991
IGM.getOptions().EnableLayoutStringValueWitnesses) {
992+
auto ty = boundGenericCharacteristics ? boundGenericCharacteristics->concreteType : concreteType;
993+
auto &typeInfo = boundGenericCharacteristics ? *boundGenericCharacteristics->TI : concreteTI;
992994
if (auto *typeLayoutEntry =
993-
concreteTI.buildTypeLayoutEntry(IGM, concreteType,
994-
/*useStructLayouts*/true)) {
995+
typeInfo.buildTypeLayoutEntry(IGM, ty, /*useStructLayouts*/true)) {
995996
auto genericSig = concreteType.getNominalOrBoundGenericNominal()
996997
->getGenericSignature();
997998
if (typeLayoutEntry->layoutString(IGM, genericSig) ||
@@ -1017,9 +1018,10 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
10171018
return addFunction(getMemCpyFunction(IGM, concreteTI));
10181019
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
10191020
IGM.getOptions().EnableLayoutStringValueWitnesses) {
1021+
auto ty = boundGenericCharacteristics ? boundGenericCharacteristics->concreteType : concreteType;
1022+
auto &typeInfo = boundGenericCharacteristics ? *boundGenericCharacteristics->TI : concreteTI;
10201023
if (auto *typeLayoutEntry =
1021-
concreteTI.buildTypeLayoutEntry(IGM, concreteType,
1022-
/*useStructLayouts*/true)) {
1024+
typeInfo.buildTypeLayoutEntry(IGM, ty, /*useStructLayouts*/true)) {
10231025
auto genericSig = concreteType.getNominalOrBoundGenericNominal()
10241026
->getGenericSignature();
10251027
if (typeLayoutEntry->layoutString(IGM, genericSig) ||
@@ -1037,9 +1039,10 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
10371039
return addFunction(getAssignWithCopyStrongFunction(IGM));
10381040
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
10391041
IGM.getOptions().EnableLayoutStringValueWitnesses) {
1042+
auto ty = boundGenericCharacteristics ? boundGenericCharacteristics->concreteType : concreteType;
1043+
auto &typeInfo = boundGenericCharacteristics ? *boundGenericCharacteristics->TI : concreteTI;
10401044
if (auto *typeLayoutEntry =
1041-
concreteTI.buildTypeLayoutEntry(IGM, concreteType,
1042-
/*useStructLayouts*/true)) {
1045+
typeInfo.buildTypeLayoutEntry(IGM, ty, /*useStructLayouts*/true)) {
10431046
auto genericSig = concreteType.getNominalOrBoundGenericNominal()
10441047
->getGenericSignature();
10451048
if (typeLayoutEntry->layoutString(IGM, genericSig) ||
@@ -1057,9 +1060,10 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
10571060
return addFunction(getAssignWithTakeStrongFunction(IGM));
10581061
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
10591062
IGM.getOptions().EnableLayoutStringValueWitnesses) {
1063+
auto ty = boundGenericCharacteristics ? boundGenericCharacteristics->concreteType : concreteType;
1064+
auto &typeInfo = boundGenericCharacteristics ? *boundGenericCharacteristics->TI : concreteTI;
10601065
if (auto *typeLayoutEntry =
1061-
concreteTI.buildTypeLayoutEntry(IGM, concreteType,
1062-
/*useStructLayouts*/true)) {
1066+
typeInfo.buildTypeLayoutEntry(IGM, ty, /*useStructLayouts*/true)) {
10631067
auto genericSig = concreteType.getNominalOrBoundGenericNominal()
10641068
->getGenericSignature();
10651069
if (typeLayoutEntry->layoutString(IGM, genericSig) ||
@@ -1077,9 +1081,10 @@ static void addValueWitness(IRGenModule &IGM, ConstantStructBuilder &B,
10771081
return addFunction(getInitWithCopyStrongFunction(IGM));
10781082
} else if (IGM.Context.LangOpts.hasFeature(Feature::LayoutStringValueWitnesses) &&
10791083
IGM.getOptions().EnableLayoutStringValueWitnesses) {
1084+
auto ty = boundGenericCharacteristics ? boundGenericCharacteristics->concreteType : concreteType;
1085+
auto &typeInfo = boundGenericCharacteristics ? *boundGenericCharacteristics->TI : concreteTI;
10801086
if (auto *typeLayoutEntry =
1081-
concreteTI.buildTypeLayoutEntry(IGM, concreteType,
1082-
/*useStructLayouts*/true)) {
1087+
typeInfo.buildTypeLayoutEntry(IGM, ty, /*useStructLayouts*/true)) {
10831088
auto genericSig = concreteType.getNominalOrBoundGenericNominal()
10841089
->getGenericSignature();
10851090
if (typeLayoutEntry->layoutString(IGM, genericSig) ||

0 commit comments

Comments
 (0)