Skip to content

Commit c19fb07

Browse files
authored
Merge pull request swiftlang#22706 from gottesmm/pr-4169ff2ff3355d2242adddbbd5a902f9e4df9729
2 parents 075f6db + fc9b28b commit c19fb07

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/SILOptimizer/pound_assert_ossa.sil

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,3 +487,51 @@ bb0(%arg : $Int64):
487487
%ret = tuple ()
488488
return %ret : $()
489489
}
490+
491+
struct BiggerStruct {
492+
var lhs: Int64
493+
var rhs: Int64
494+
}
495+
496+
// This tests the same bug as the previous two tests but adds in missing code
497+
// coverage of destructure_tuples, tuple_extracts, and tuples.
498+
sil [ossa] @doubleWriteTupleElementDestructureWithMoreFeeling : $@convention(thin) (BiggerStruct) -> () {
499+
bb0(%arg : $BiggerStruct):
500+
// Allocate and initialize the tuple to (1, 2).
501+
%0 = alloc_stack $(BiggerStruct, BiggerStruct), var, name "tup"
502+
%1 = tuple_element_addr %0 : $*(BiggerStruct, BiggerStruct), 0
503+
%3 = integer_literal $Builtin.Int64, 1
504+
%3a = struct $Int64 (%3 : $Builtin.Int64)
505+
%4 = struct $BiggerStruct (%3a : $Int64, %3a : $Int64)
506+
store %4 to [trivial] %1 : $*BiggerStruct
507+
508+
%2 = tuple_element_addr %0 : $*(BiggerStruct, BiggerStruct), 1
509+
%6 = integer_literal $Builtin.Int64, 2
510+
%6a = struct $Int64 (%6 : $Builtin.Int64)
511+
%7 = struct $BiggerStruct (%6a : $Int64, %6a : $Int64)
512+
store %7 to [trivial] %2 : $*BiggerStruct
513+
514+
// Read the first element from the tuple.
515+
%10 = tuple_element_addr %0 : $*(BiggerStruct, BiggerStruct), 1
516+
%11 = load [trivial] %10 : $*BiggerStruct
517+
518+
// Check that the first element is what we put in.
519+
(%13, %13a) = destructure_struct %11 : $BiggerStruct
520+
%13b = tuple(%13 : $Int64, %13a : $Int64)
521+
(%13c, %13d) = destructure_tuple %13b : $(Int64, Int64)
522+
%13e = tuple(%13c : $Int64, %13d : $Int64)
523+
%13f = tuple_extract %13e : $(Int64, Int64), 0
524+
%13g = struct_extract %13f : $Int64, #Int64._value
525+
%14 = builtin "cmp_eq_Int64"(%3 : $Builtin.Int64, %13g : $Builtin.Int64) : $Builtin.Int1
526+
%14a = builtin "cmp_eq_Int64"(%6 : $Builtin.Int64, %13g : $Builtin.Int64) : $Builtin.Int1
527+
%15 = string_literal utf8 ""
528+
// Make sure that we are able to simplify this completely.
529+
// expected-error @+1 {{assertion failed}}
530+
%16 = builtin "poundAssert"(%14 : $Builtin.Int1, %15 : $Builtin.RawPointer) : $()
531+
// Make sure that this matches.
532+
%17 = builtin "poundAssert"(%14a : $Builtin.Int1, %15 : $Builtin.RawPointer) : $()
533+
// Deallocate and return.
534+
dealloc_stack %0 : $*(BiggerStruct, BiggerStruct)
535+
%ret = tuple ()
536+
return %ret : $()
537+
}

0 commit comments

Comments
 (0)