Skip to content

Commit a9302ec

Browse files
committed
[WIP] Reproduce SR-13263 crash.
Details in comments in test/DebugInfo/sr13263.swift.
1 parent 396709c commit a9302ec

7 files changed

+9748
-0
lines changed

test/DebugInfo/sr13263-function.ll

+1,715
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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"'
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 except it's a single file test case instead of a multi-file one.
3+
// The crash does not reproduce.
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 does not crash:
8+
// RUN: %target-swiftc_driver -O -g -I %t -c %s -o /dev/null
9+
10+
import _Differentiation
11+
12+
public struct S<T> {
13+
class C {}
14+
let c: C
15+
internal var b: Bool
16+
}
17+
18+
extension S: AdditiveArithmetic {
19+
public static var zero: S { fatalError() }
20+
21+
public static func == (_ lhs: S, _ rhs: S) -> Bool { fatalError() }
22+
public static func + (_ lhs: S, _ rhs: S) -> S { fatalError() }
23+
public static func - (_ lhs: S, _ rhs: S) -> S { fatalError() }
24+
}
25+
26+
extension S: Differentiable {
27+
public typealias TangentVector = S
28+
}
29+
30+
import _Differentiation
31+
import M
32+
33+
struct T: Differentiable {
34+
var u1: U
35+
var u2: U
36+
}
37+
38+
struct U: Differentiable {
39+
var s: S<Float>
40+
var v: V
41+
}
42+
43+
struct V: Differentiable {
44+
var s: S<Float>
45+
}

0 commit comments

Comments
 (0)