Skip to content

Commit 44f13d8

Browse files
authored
Merge pull request #5249 from gottesmm/rdar28536812
2 parents 70ee164 + 472b57a commit 44f13d8

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,29 +2753,34 @@ namespace {
27532753
OS << ")";
27542754
}
27552755

2756+
void printMetatypeRepresentation(MetatypeRepresentation representation) {
2757+
OS << " ";
2758+
switch (representation) {
2759+
case MetatypeRepresentation::Thin:
2760+
OS << "@thin";
2761+
break;
2762+
case MetatypeRepresentation::Thick:
2763+
OS << "@thick";
2764+
break;
2765+
case MetatypeRepresentation::ObjC:
2766+
OS << "@objc";
2767+
break;
2768+
}
2769+
}
2770+
27562771
void visitMetatypeType(MetatypeType *T, StringRef label) {
27572772
printCommon(T, label, "metatype_type");
2758-
if (T->hasRepresentation()) {
2759-
OS << " ";
2760-
switch (T->getRepresentation()) {
2761-
case MetatypeRepresentation::Thin:
2762-
OS << "@thin";
2763-
break;
2764-
case MetatypeRepresentation::Thick:
2765-
OS << "@thick";
2766-
break;
2767-
case MetatypeRepresentation::ObjC:
2768-
OS << "@objc";
2769-
break;
2770-
}
2771-
}
2773+
if (T->hasRepresentation())
2774+
printMetatypeRepresentation(T->getRepresentation());
27722775
printRec(T->getInstanceType());
27732776
OS << ")";
27742777
}
27752778

27762779
void visitExistentialMetatypeType(ExistentialMetatypeType *T,
27772780
StringRef label) {
27782781
printCommon(T, label, "existential_metatype_type");
2782+
if (T->hasRepresentation())
2783+
printMetatypeRepresentation(T->getRepresentation());
27792784
printRec(T->getInstanceType());
27802785
OS << ")";
27812786
}

lib/SIL/SILVerifier.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,8 +1491,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
14911491
if (auto dynamicSelf = dyn_cast<DynamicSelfType>(formalObjectType)) {
14921492
formalObjectType = dynamicSelf->getSelfType()->getCanonicalType();
14931493
}
1494-
return ((loweredOptionalKind == formalOptionalKind) &&
1495-
loweredObjectType == formalObjectType);
1494+
return loweredOptionalKind == formalOptionalKind &&
1495+
isLoweringOf(SILType::getPrimitiveAddressType(loweredObjectType),
1496+
formalObjectType);
14961497
}
14971498

14981499
// Metatypes preserve their instance type through lowering.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-sil-opt -module-name Swift %s
2+
// REQUIRES: asserts
3+
//
4+
// Make sure that we properly verify the lowering of optional value
5+
// metatypes. This shouldn't crash.
6+
//
7+
// rdar://28536812
8+
9+
enum Optional<T> {
10+
case none
11+
case some(T)
12+
}
13+
14+
sil @foo : $@convention(thin) () -> () {
15+
%0 = enum $Optional<@thick Any.Type>, #Optional.none!enumelt
16+
%1 = alloc_stack $Optional<@thick Any.Type>
17+
store %0 to %1 : $*Optional<@thick Any.Type>
18+
%2 = value_metatype $@thick Optional<Any.Type>.Type, %1 : $*Optional<@thick Any.Type>
19+
dealloc_stack %1 : $*Optional<@thick Any.Type>
20+
%3 = tuple()
21+
return %3 : $()
22+
}

0 commit comments

Comments
 (0)