Skip to content

[sil-verifier] Verify correctly that lowered SIL optional types are lowered types of formal optional types. #5249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2753,29 +2753,34 @@ namespace {
OS << ")";
}

void printMetatypeRepresentation(MetatypeRepresentation representation) {
OS << " ";
switch (representation) {
case MetatypeRepresentation::Thin:
OS << "@thin";
break;
case MetatypeRepresentation::Thick:
OS << "@thick";
break;
case MetatypeRepresentation::ObjC:
OS << "@objc";
break;
}
}

void visitMetatypeType(MetatypeType *T, StringRef label) {
printCommon(T, label, "metatype_type");
if (T->hasRepresentation()) {
OS << " ";
switch (T->getRepresentation()) {
case MetatypeRepresentation::Thin:
OS << "@thin";
break;
case MetatypeRepresentation::Thick:
OS << "@thick";
break;
case MetatypeRepresentation::ObjC:
OS << "@objc";
break;
}
}
if (T->hasRepresentation())
printMetatypeRepresentation(T->getRepresentation());
printRec(T->getInstanceType());
OS << ")";
}

void visitExistentialMetatypeType(ExistentialMetatypeType *T,
StringRef label) {
printCommon(T, label, "existential_metatype_type");
if (T->hasRepresentation())
printMetatypeRepresentation(T->getRepresentation());
printRec(T->getInstanceType());
OS << ")";
}
Expand Down
5 changes: 3 additions & 2 deletions lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1491,8 +1491,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
if (auto dynamicSelf = dyn_cast<DynamicSelfType>(formalObjectType)) {
formalObjectType = dynamicSelf->getSelfType()->getCanonicalType();
}
return ((loweredOptionalKind == formalOptionalKind) &&
loweredObjectType == formalObjectType);
return loweredOptionalKind == formalOptionalKind &&
isLoweringOf(SILType::getPrimitiveAddressType(loweredObjectType),
formalObjectType);
}

// Metatypes preserve their instance type through lowering.
Expand Down
22 changes: 22 additions & 0 deletions test/SIL/verifier-value-metatype-lowering.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %target-sil-opt -module-name Swift %s
// REQUIRES: asserts
//
// Make sure that we properly verify the lowering of optional value
// metatypes. This shouldn't crash.
//
// rdar://28536812

enum Optional<T> {
case none
case some(T)
}

sil @foo : $@convention(thin) () -> () {
%0 = enum $Optional<@thick Any.Type>, #Optional.none!enumelt
%1 = alloc_stack $Optional<@thick Any.Type>
store %0 to %1 : $*Optional<@thick Any.Type>
%2 = value_metatype $@thick Optional<Any.Type>.Type, %1 : $*Optional<@thick Any.Type>
dealloc_stack %1 : $*Optional<@thick Any.Type>
%3 = tuple()
return %3 : $()
}