Skip to content

Commit aee9da5

Browse files
authored
Merge pull request #64489 from slavapestov/fix-pack-archetype-folding-irgen
IRGen: Various minor fixes
2 parents eb6dc22 + b71cf4c commit aee9da5

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

lib/IRGen/GenPack.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ static void emitPackExpansionPack(
381381
IGF.Builder.CreateCondBr(cond, loop, rest);
382382

383383
IGF.Builder.emitBlock(loop);
384+
ConditionalDominanceScope condition(IGF);
384385

385386
auto *element = elementForIndex(phi);
386387

@@ -824,6 +825,8 @@ llvm::Value *irgen::emitTypeMetadataPackElementRef(
824825
// (1) Emit check_i {{
825826
IGF.Builder.emitBlock(checkBounds);
826827

828+
ConditionalDominanceScope dominanceScope(IGF);
829+
827830
// The upper bound for the current pack expansion. Exclusive.
828831
llvm::Value *upperBound = nullptr;
829832
llvm::Value *condition = nullptr;

lib/IRGen/GenTuple.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,10 @@ Address irgen::projectTupleElementAddressByDynamicIndex(IRGenFunction &IGF,
565565
llvm::Value *offset = loadTupleOffsetFromMetadata(IGF, metadata, index);
566566
auto *gep =
567567
IGF.emitByteOffsetGEP(tuple.getAddress(), offset, IGF.IGM.OpaqueTy);
568-
return Address(gep, IGF.IGM.OpaqueTy, IGF.IGM.getPointerAlignment());
568+
auto elementAddress = Address(gep, IGF.IGM.OpaqueTy,
569+
IGF.IGM.getPointerAlignment());
570+
return IGF.Builder.CreateElementBitCast(elementAddress,
571+
IGF.IGM.getStorageType(elementType));
569572
}
570573

571574
Optional<Size> irgen::getFixedTupleElementOffset(IRGenModule &IGM,

lib/IRGen/GenType.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,14 +1966,14 @@ const TypeInfo &TypeConverter::getCompleteTypeInfo(CanType T) {
19661966
}
19671967

19681968
ArchetypeType *TypeConverter::getExemplarArchetype(ArchetypeType *t) {
1969-
// Get the primary archetype.
1970-
auto root = t->getRoot();
1971-
1972-
// If there is no primary (IOW, it's an opened archetype), the archetype is
1973-
// an exemplar.
1974-
if (!isa<PrimaryArchetypeType>(root) && !isa<VariadicSequenceType>(root))
1969+
if (isa<LocalArchetypeType>(t) || isa<OpaqueTypeArchetypeType>(t))
19751970
return t;
19761971

1972+
assert(isa<PrimaryArchetypeType>(t) || isa<PackArchetypeType>(t));
1973+
1974+
// Get the root archetype.
1975+
auto root = t->getRoot();
1976+
19771977
// Retrieve the generic environment of the archetype.
19781978
auto genericEnv = root->getGenericEnvironment();
19791979

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend -emit-ir %s -enable-experimental-feature VariadicGenerics
2+
3+
// Because of -enable-experimental-feature VariadicGenerics
4+
// REQUIRES: asserts
5+
6+
// This would crash.
7+
public struct G<T> {}
8+
9+
public struct GG<each T> {
10+
public var variables: (repeat G<each T>)
11+
12+
public init() {
13+
fatalError()
14+
}
15+
}

0 commit comments

Comments
 (0)