Skip to content

Commit c6be347

Browse files
committed
SILCombine: fix metatype simplification
Don't reuse argument metadata if it's an indirect argument. Fixes a verifier crash. https://bugs.swift.org/browse/SR-13731 rdar://problem/70338666
1 parent ce90767 commit c6be347

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/SILOptimizer/Analysis/SimplifyInstruction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ SILValue InstSimplifier::visitMetatypeInst(MetatypeInst *MI) {
488488
|| instanceType.getStructOrBoundGenericStruct()
489489
|| instanceType.getEnumOrBoundGenericEnum()) {
490490
for (SILArgument *argument : MI->getFunction()->getArguments()) {
491-
if (argument->getType().getASTType() == metaType)
491+
if (argument->getType().getASTType() == metaType &&
492+
argument->getType().isObject())
492493
return argument;
493494
}
494495
}

test/SILOptimizer/sil_simplify_instrs.sil

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,16 @@ bb0(%0 : $@thick SpecialEnum.Type):
371371
%5 = struct $Bool (%4 : $Builtin.Int1)
372372
return %5 : $Bool
373373
}
374+
375+
// CHECK-LABEL: sil @dontSimplifyIndirectMetatype : $@convention(thin) () -> @out @thick Int.Type {
376+
// CHECK: [[MT:%[0-9]+]] = metatype $@thick Int.Type
377+
// CHECK: store [[MT]] to %0
378+
// CHECK-LABEL: } // end sil function 'dontSimplifyIndirectMetatype'
379+
sil @dontSimplifyIndirectMetatype : $@convention(thin) () -> @out @thick Int.Type {
380+
bb0(%0 : $*@thick Int.Type):
381+
%1 = metatype $@thick Int.Type
382+
store %1 to %0 : $*@thick Int.Type
383+
%3 = tuple ()
384+
return %3 : $()
385+
}
386+

0 commit comments

Comments
 (0)