Skip to content

Commit 6cbf33a

Browse files
authored
Merge pull request #77111 from clackary/fix/6.0-cherrypick-72619
[6.0] Ensure LoadableByAddress rewrites pointer_to_address
2 parents f4db3a2 + 1457fe6 commit 6cbf33a

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,8 @@ void LargeValueVisitor::visitAllocStackInst(AllocStackInst *instr) {
10031003

10041004
void LargeValueVisitor::visitPointerToAddressInst(PointerToAddressInst *instr) {
10051005
SILType currSILType = instr->getType().getObjectType();
1006-
if (getInnerFunctionType(currSILType)) {
1006+
if (pass.containsDifferentFunctionSignature(pass.F->getLoweredFunctionType(),
1007+
currSILType)) {
10071008
pass.pointerToAddrkInstsToMod.push_back(instr);
10081009
}
10091010
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// REQUIRES: differentiable_programming
2+
// RUN: %target-swift-frontend -emit-ir -verify %s
3+
4+
// This used to trigger an assertion due to LoadableByAddress incorrectly doing incorrect transforms
5+
// around linear map tuple users (pointer_to_address).
6+
7+
import _Differentiation
8+
struct H: Differentiable {}
9+
protocol J: Differentiable {}
10+
struct L: Differentiable {
11+
var p: [P]
12+
@differentiable(reverse) func s() -> H {
13+
var m = 0.0
14+
for i in 0 ..< withoutDerivative(at: p.count) {
15+
m += p[i].a
16+
m += p[i].a
17+
m += p[i].a
18+
m += p[i].a
19+
}
20+
return P.g(p: P(a: 0.0, b: 0.0, c: 0.0, d: m), z: L( p: self.p)).w
21+
}
22+
}
23+
struct P: J {
24+
var a = 0.0
25+
var b = 0.0
26+
var c = 0.0
27+
var d = 0.0
28+
var e = 0.0
29+
@differentiable(reverse) static func g(p: P, z: L) -> Y<P> {return Y<P>(w: H())}
30+
}
31+
struct Y<U: J>: Differentiable {var w: H = H()}

0 commit comments

Comments
 (0)