|
| 1 | +// RUN: %sil-opt -temp-rvalue-opt %s -o /dev/null |
| 2 | + |
| 3 | +// This test exposes a bug in the MemBehavior cache invalidation mechanism. |
| 4 | +// With this bug, the optimizer aborts with a SIL memory lifetime failure |
| 5 | +// (only on linux). |
| 6 | + |
| 7 | +sil_stage canonical |
| 8 | + |
| 9 | +import Builtin |
| 10 | +import Swift |
| 11 | +import SwiftShims |
| 12 | + |
| 13 | +public struct Complex<RealType> where RealType : FloatingPoint { |
| 14 | + @usableFromInline |
| 15 | + @_hasStorage internal var x: RealType { get set } |
| 16 | + @usableFromInline |
| 17 | + @_hasStorage internal var y: RealType { get set } |
| 18 | + init(_ real: RealType, _ imaginary: RealType) |
| 19 | +} |
| 20 | + |
| 21 | +extension Complex { |
| 22 | + var phase: RealType { get } |
| 23 | +} |
| 24 | + |
| 25 | +extension Complex { |
| 26 | + public static func log(_ z: Complex<RealType>, _ b: Bool) -> Complex<RealType> |
| 27 | +} |
| 28 | + |
| 29 | +sil [ossa] @callee : $@convention(method) <RealType where RealType : FloatingPoint> (@in_guaranteed Complex<RealType>) -> @out RealType |
| 30 | + |
| 31 | +sil [ossa] @test : $@convention(method) <RealType where RealType : FloatingPoint> (@in_guaranteed Complex<RealType>, Bool, @thin Complex<RealType>.Type) -> @out Complex<RealType> { |
| 32 | +bb0(%0 : $*Complex<RealType>, %1 : $*Complex<RealType>, %2 : $Bool, %3 : $@thin Complex<RealType>.Type): |
| 33 | + debug_value_addr %1 : $*Complex<RealType>, let, name "z", argno 1 |
| 34 | + debug_value %2 : $Bool, let, name "b", argno 2 |
| 35 | + debug_value %3 : $@thin Complex<RealType>.Type, let, name "self", argno 3 |
| 36 | + %7 = alloc_stack $RealType, let, name "θ" |
| 37 | + %8 = alloc_stack $Complex<RealType> |
| 38 | + copy_addr %1 to [initialization] %8 : $*Complex<RealType> |
| 39 | + %10 = function_ref @callee : $@convention(method) <τ_0_0 where τ_0_0 : FloatingPoint> (@in_guaranteed Complex<τ_0_0>) -> @out τ_0_0 |
| 40 | + %11 = apply %10<RealType>(%7, %8) : $@convention(method) <τ_0_0 where τ_0_0 : FloatingPoint> (@in_guaranteed Complex<τ_0_0>) -> @out τ_0_0 |
| 41 | + destroy_addr %8 : $*Complex<RealType> |
| 42 | + dealloc_stack %8 : $*Complex<RealType> |
| 43 | + %14 = integer_literal $Builtin.Int1, -1 |
| 44 | + %15 = struct_extract %2 : $Bool, #Bool._value |
| 45 | + %16 = builtin "cmp_eq_Int1"(%15 : $Builtin.Int1, %14 : $Builtin.Int1) : $Builtin.Int1 |
| 46 | + cond_br %16, bb1, bb2 |
| 47 | + |
| 48 | +bb1: |
| 49 | + %18 = metatype $@thick RealType.Type |
| 50 | + %19 = alloc_stack $RealType |
| 51 | + %20 = witness_method $RealType, #FloatingPoint.infinity!getter : <Self where Self : FloatingPoint> (Self.Type) -> () -> Self : $@convention(witness_method: FloatingPoint) <τ_0_0 where τ_0_0 : FloatingPoint> (@thick τ_0_0.Type) -> @out τ_0_0 |
| 52 | + %21 = apply %20<RealType>(%19, %18) : $@convention(witness_method: FloatingPoint) <τ_0_0 where τ_0_0 : FloatingPoint> (@thick τ_0_0.Type) -> @out τ_0_0 |
| 53 | + %22 = alloc_stack $RealType |
| 54 | + copy_addr [take] %7 to [initialization] %22 : $*RealType |
| 55 | + %24 = alloc_stack $Complex<RealType> |
| 56 | + %25 = alloc_stack $RealType |
| 57 | + copy_addr [take] %19 to [initialization] %25 : $*RealType |
| 58 | + %27 = struct_element_addr %24 : $*Complex<RealType>, #Complex.x |
| 59 | + copy_addr [take] %25 to [initialization] %27 : $*RealType |
| 60 | + dealloc_stack %25 : $*RealType |
| 61 | + %30 = alloc_stack $RealType |
| 62 | + copy_addr [take] %22 to [initialization] %30 : $*RealType |
| 63 | + %32 = struct_element_addr %24 : $*Complex<RealType>, #Complex.y |
| 64 | + copy_addr [take] %30 to [initialization] %32 : $*RealType |
| 65 | + dealloc_stack %30 : $*RealType |
| 66 | + copy_addr %24 to [initialization] %0 : $*Complex<RealType> |
| 67 | + destroy_addr %24 : $*Complex<RealType> |
| 68 | + dealloc_stack %24 : $*Complex<RealType> |
| 69 | + %38 = tuple () |
| 70 | + dealloc_stack %22 : $*RealType |
| 71 | + dealloc_stack %19 : $*RealType |
| 72 | + dealloc_stack %7 : $*RealType |
| 73 | + br bb3 |
| 74 | + |
| 75 | +bb2: |
| 76 | + %43 = metatype $@thick RealType.Type |
| 77 | + %44 = alloc_stack $RealType |
| 78 | + %45 = witness_method $RealType, #FloatingPoint.infinity!getter : <Self where Self : FloatingPoint> (Self.Type) -> () -> Self : $@convention(witness_method: FloatingPoint) <τ_0_0 where τ_0_0 : FloatingPoint> (@thick τ_0_0.Type) -> @out τ_0_0 |
| 79 | + %46 = apply %45<RealType>(%44, %43) : $@convention(witness_method: FloatingPoint) <τ_0_0 where τ_0_0 : FloatingPoint> (@thick τ_0_0.Type) -> @out τ_0_0 |
| 80 | + %47 = alloc_stack $RealType |
| 81 | + copy_addr [take] %7 to [initialization] %47 : $*RealType |
| 82 | + %49 = alloc_stack $Complex<RealType> |
| 83 | + %50 = alloc_stack $RealType |
| 84 | + copy_addr [take] %44 to [initialization] %50 : $*RealType |
| 85 | + %52 = struct_element_addr %49 : $*Complex<RealType>, #Complex.x |
| 86 | + copy_addr [take] %50 to [initialization] %52 : $*RealType |
| 87 | + dealloc_stack %50 : $*RealType |
| 88 | + %55 = alloc_stack $RealType |
| 89 | + copy_addr [take] %47 to [initialization] %55 : $*RealType |
| 90 | + %57 = struct_element_addr %49 : $*Complex<RealType>, #Complex.y |
| 91 | + copy_addr [take] %55 to [initialization] %57 : $*RealType |
| 92 | + dealloc_stack %55 : $*RealType |
| 93 | + copy_addr %49 to [initialization] %0 : $*Complex<RealType> |
| 94 | + destroy_addr %49 : $*Complex<RealType> |
| 95 | + dealloc_stack %49 : $*Complex<RealType> |
| 96 | + %63 = tuple () |
| 97 | + dealloc_stack %47 : $*RealType |
| 98 | + dealloc_stack %44 : $*RealType |
| 99 | + dealloc_stack %7 : $*RealType |
| 100 | + br bb3 |
| 101 | + |
| 102 | +bb3: |
| 103 | + %68 = tuple () |
| 104 | + return %68 : $() |
| 105 | +} |
| 106 | + |
| 107 | +sil_property #Complex.x<τ_0_0 where τ_0_0 : FloatingPoint> () |
| 108 | +sil_property #Complex.y<τ_0_0 where τ_0_0 : FloatingPoint> () |
| 109 | + |
| 110 | + |
0 commit comments