Skip to content

Commit e8cac8b

Browse files
authored
Merge pull request #40503 from rxwei/fix-ad-lexical-borrow-scopes
[AutoDiff] Use auto-generated locations for temporary allocations.
2 parents f2a416e + cf2ccf1 commit e8cac8b

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

lib/SILOptimizer/Differentiation/TangentBuilder.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ void TangentBuilder::emitZeroIntoBuffer(SILLocation loc, SILValue buffer,
6161
SILValue TangentBuilder::emitZero(SILLocation loc, CanType type) {
6262
auto silType = getModule().Types.getLoweredLoadableType(
6363
type, TypeExpansionContext::minimal(), getModule());
64-
auto *alloc = createAllocStack(loc, silType);
64+
auto tempAllocLoc = RegularLocation::getAutoGeneratedLocation();
65+
auto *alloc = createAllocStack(tempAllocLoc, silType);
6566
emitZeroIntoBuffer(loc, alloc, IsInitialization);
6667
auto zeroValue = emitLoadValueOperation(
6768
loc, alloc, LoadOwnershipQualifier::Take);
@@ -176,9 +177,10 @@ SILValue TangentBuilder::emitAdd(SILLocation loc, SILValue lhs, SILValue rhs) {
176177
auto lhsCopy = emitCopyValueOperation(loc, lhs);
177178
auto rhsCopy = emitCopyValueOperation(loc, rhs);
178179
// Allocate buffers for inputs and output.
179-
auto *resultBuf = createAllocStack(loc, type);
180-
auto *lhsBuf = createAllocStack(loc, type);
181-
auto *rhsBuf = createAllocStack(loc, type);
180+
auto tempAllocLoc = RegularLocation::getAutoGeneratedLocation();
181+
auto *resultBuf = createAllocStack(tempAllocLoc, type);
182+
auto *lhsBuf = createAllocStack(tempAllocLoc, type);
183+
auto *rhsBuf = createAllocStack(tempAllocLoc, type);
182184
// Initialize input buffers.
183185
emitStoreValueOperation(loc, lhsCopy, lhsBuf,
184186
StoreOwnershipQualifier::Init);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-build-swift %s
2+
// RUN: %target-swift-frontend -c -g -Xllvm -verify-di-holes=true %s
3+
4+
// SR-15566: Differentiable functions with control flow yield an assertion failure: "location is a VarDecl, but SILDebugVariable is empty"
5+
6+
import _Differentiation
7+
8+
public struct Test: Differentiable {
9+
public var v1: [[Float]]
10+
11+
@differentiable(reverse)
12+
public init(v1: [[Float]]) {
13+
if v1.count != 2 {
14+
fatalError("Mismatched counts")
15+
}
16+
self.v1 = v1
17+
}
18+
}
19+
20+
// Assertion failed: ((!dyn_cast_or_null<VarDecl>(Loc.getAsASTNode<Decl>()) || Var) && "location is a VarDecl, but SILDebugVariable is empty"), function createAllocStack, file SILBuilder.h, line 389.

test/AutoDiff/validation-test/array.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-borrow-scopes=false)
1+
// RUN: %target-run-simple-swift
22

33
// REQUIRES: executable_test
44

test/AutoDiff/validation-test/optional.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-borrow-scopes=false)
1+
// RUN: %target-run-simple-swift
22

33
// REQUIRES: executable_test
44

test/AutoDiff/validation-test/optional_property.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-borrow-scopes=false)
2-
// RUN: %target-swift-emit-sil -Xllvm -debug-only=differentiation -enable-lexical-borrow-scopes=false -module-name null -o /dev/null 2>&1 %s | %FileCheck %s
1+
// RUN: %target-run-simple-swift
2+
// RUN: %target-swift-emit-sil -Xllvm -debug-only=differentiation -module-name null -o /dev/null 2>&1 %s | %FileCheck %s
33

44
// REQUIRES: executable_test
55
// REQUIRES: asserts

0 commit comments

Comments
 (0)