Skip to content

Commit a434ee8

Browse files
authored
[AutoDiff] Fix PullbackCloner tangent value category mismatch crash (#33512)
Fix semantic member getter pullback generation crash due to tangent value category mismatch. Resolves SR-13411.
1 parent 4cfaeee commit a434ee8

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ static CanSILFunctionType getAutoDiffDifferentialType(
407407
// result's convention is indirect.
408408
if (tl.isAddressOnly() && !isIndirectFormalResult(origResConv)) {
409409
switch (origResConv) {
410+
case ResultConvention::Unowned:
410411
case ResultConvention::Owned:
411412
return ResultConvention::Indirect;
412413
default:

lib/SILOptimizer/Differentiation/PullbackCloner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@ bool PullbackCloner::Implementation::runForSemanticMemberGetter() {
24312431

24322432
// Switch based on the base tangent struct's value category.
24332433
// TODO(TF-1255): Simplify using unified adjoint value data structure.
2434-
switch (tangentVectorSILTy.getCategory()) {
2434+
switch (getTangentValueCategory(origSelf)) {
24352435
case SILValueCategory::Object: {
24362436
auto adjResult = getAdjointValue(origEntry, origResult);
24372437
switch (adjResult.getKind()) {
@@ -2472,7 +2472,7 @@ bool PullbackCloner::Implementation::runForSemanticMemberGetter() {
24722472
if (field == tanField) {
24732473
// Switch based on the property's value category.
24742474
// TODO(TF-1255): Simplify using unified adjoint value data structure.
2475-
switch (origResult->getType().getCategory()) {
2475+
switch (getTangentValueCategory(origResult)) {
24762476
case SILValueCategory::Object: {
24772477
auto adjResult = getAdjointValue(origEntry, origResult);
24782478
auto adjResultValue = materializeAdjointDirect(adjResult, pbLoc);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-build-swift %s
2+
// REQUIRES: asserts
3+
4+
// SR-13411: Semantic member getter pullback generation crash due to tangent value category mismatch
5+
6+
import _Differentiation
7+
8+
struct Dense: Differentiable {
9+
@differentiable
10+
var bias: Float?
11+
}
12+

0 commit comments

Comments
 (0)