Skip to content

Commit 2ad4a60

Browse files
authored
Ensure LoadableByAddress rewrites pointer_to_address (#72619)
if the target address is address of tuple type that should be rewritten. Fixes #72363
1 parent bbfdf7b commit 2ad4a60

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
@@ -997,7 +997,8 @@ void LargeValueVisitor::visitAllocStackInst(AllocStackInst *instr) {
997997

998998
void LargeValueVisitor::visitPointerToAddressInst(PointerToAddressInst *instr) {
999999
SILType currSILType = instr->getType().getObjectType();
1000-
if (getInnerFunctionType(currSILType)) {
1000+
if (pass.containsDifferentFunctionSignature(pass.F->getLoweredFunctionType(),
1001+
currSILType)) {
10011002
pass.pointerToAddrkInstsToMod.push_back(instr);
10021003
}
10031004
}
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)