|
| 1 | +// SR-13263: Debug info crash related to optimizations/LoadableByAddress and `Differentiable` derived conformances. |
| 2 | +// This test is a copy of test/DebugInfo/sr13263.swift where `Differentiable` derived conformances are manually written. |
| 3 | +// The crash does not reproduce if the `T: Differentiable` derived conformance is written out by hand. |
| 4 | + |
| 5 | +// RUN: %empty-directory(%t) |
| 6 | +// RUN: %target-swiftc_driver -DM -emit-module -emit-module-path %t/M.swiftmodule %s -module-name M |
| 7 | +// NOTE: The following command crashes: |
| 8 | +// RUN: not --crash %target-swiftc_driver -O -g -I %t -c %s -o /dev/null |
| 9 | + |
| 10 | +#if M |
| 11 | +import _Differentiation |
| 12 | + |
| 13 | +public struct S<T> { |
| 14 | + class C {} |
| 15 | + let c: C |
| 16 | + internal var b: Bool |
| 17 | +} |
| 18 | + |
| 19 | +extension S: AdditiveArithmetic { |
| 20 | + public static var zero: S { fatalError() } |
| 21 | + |
| 22 | + public static func == (_ lhs: S, _ rhs: S) -> Bool { fatalError() } |
| 23 | + public static func + (_ lhs: S, _ rhs: S) -> S { fatalError() } |
| 24 | + public static func - (_ lhs: S, _ rhs: S) -> S { fatalError() } |
| 25 | +} |
| 26 | + |
| 27 | +extension S: Differentiable { |
| 28 | + public typealias TangentVector = S |
| 29 | +} |
| 30 | + |
| 31 | +#else |
| 32 | +import _Differentiation |
| 33 | +import M |
| 34 | + |
| 35 | +struct T: Differentiable { |
| 36 | + var u1: U |
| 37 | + var u2: U |
| 38 | + |
| 39 | + // NOTE: The crash does not reproduce if the `T: Differentiable` derived conformance is written out by hand. |
| 40 | + /* |
| 41 | + struct TangentVector: Differentiable, AdditiveArithmetic { |
| 42 | + var u1: U.TangentVector |
| 43 | + var u2: U.TangentVector |
| 44 | + typealias TangentVector = Self |
| 45 | + |
| 46 | + static func + (lhs: Self, rhs: Self) -> Self { Self(u1: lhs.u1 + rhs.u1, u2: lhs.u2 + rhs.u2) } |
| 47 | + static func - (lhs: Self, rhs: Self) -> Self { Self(u1: lhs.u1 - rhs.u1, u2: lhs.u2 - rhs.u2) } |
| 48 | + static var zero: Self { Self(u1: .zero, u2: .zero) } |
| 49 | + } |
| 50 | + |
| 51 | + mutating func move(along direction: TangentVector) { |
| 52 | + u1.move(along: direction.u1) |
| 53 | + u2.move(along: direction.u2) |
| 54 | + } |
| 55 | + */ |
| 56 | +} |
| 57 | + |
| 58 | +struct U: Differentiable { |
| 59 | + var s: S<Float> |
| 60 | + var v: V |
| 61 | + |
| 62 | + // NOTE: Code below is a manually written version of compiler-synthesized code |
| 63 | + // for `Differentiable` derived conformances. |
| 64 | + struct TangentVector: Differentiable, AdditiveArithmetic { |
| 65 | + var s: S<Float>.TangentVector |
| 66 | + var v: V.TangentVector |
| 67 | + typealias TangentVector = Self |
| 68 | + |
| 69 | + static func + (lhs: Self, rhs: Self) -> Self { Self(s: lhs.s + rhs.s, v: lhs.v + rhs.v) } |
| 70 | + static func - (lhs: Self, rhs: Self) -> Self { Self(s: lhs.s - rhs.s, v: lhs.v - rhs.v) } |
| 71 | + static var zero: Self { Self(s: .zero, v: .zero) } |
| 72 | + } |
| 73 | + |
| 74 | + mutating func move(along direction: TangentVector) { |
| 75 | + s.move(along: direction.s) |
| 76 | + v.move(along: direction.v) |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +struct V: Differentiable { |
| 81 | + var s: S<Float> |
| 82 | + |
| 83 | + // NOTE: Code below is a manually written version of compiler-synthesized code |
| 84 | + // for `Differentiable` derived conformances. |
| 85 | + struct TangentVector: Differentiable, AdditiveArithmetic { |
| 86 | + var s: S<Float>.TangentVector |
| 87 | + typealias TangentVector = Self |
| 88 | + |
| 89 | + static func + (lhs: Self, rhs: Self) -> Self { Self(s: lhs.s + rhs.s) } |
| 90 | + static func - (lhs: Self, rhs: Self) -> Self { Self(s: lhs.s - rhs.s) } |
| 91 | + static var zero: Self { Self(s: .zero) } |
| 92 | + } |
| 93 | + |
| 94 | + mutating func move(along direction: TangentVector) { |
| 95 | + s.move(along: direction.s) |
| 96 | + } |
| 97 | +} |
| 98 | +#endif |
| 99 | + |
| 100 | +// swift-frontend: swift-dev/llvm-project/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp:572: void llvm::DwarfExpression::addFragmentOffset(const llvm::DIExpression *): Assertion `FragmentOffset >= OffsetInBits && "overlapping or duplicate fragments"' failed. |
| 101 | +// Stack dump: |
| 102 | +// 1. Swift version 5.3-dev (LLVM 6d510c802af0d59, Swift 3e090b483352b3c) |
| 103 | +// 2. Running pass 'Function Pass Manager' on module '/dev/null'. |
| 104 | +// 3. Running pass 'X86 Assembly Printer' on function '@"$s4null1TV4move5alongyAC13TangentVectorV_tF"' |
0 commit comments