Files
swift-mirror/test/AutoDiff/compiler_crashers_fixed/58660-conflicting-debug-info-inlining.swift
Anton Korobeynikov 4f05096594 Propagate location from destination alloca in salvageDebugInfo(). (#58763)
`salvageDebugInfo` is called during SIL Mem2Reg and could produce misleading debug info in the following case:

```
%a = alloc_stack $MyModel.TangentVector, var, name "self", argno 1, implicit, loc "debug2.swift":37:17 ...
...
store %b to %a : $*MyModel.TangentVector
```

Such SIL could be created as a result of inlining (where store comes from the inlined function).
Before this patch we'd end with `debug_value` instruction with variable information, but without or incorrect location.

This caused LLVM IR debug info verifier assertions when there might be another instruction with complete debug info (including location) for the same argument.

After this patch we always reuse it from destination alloca

Fixes #58660
2022-05-11 13:28:23 -07:00

60 lines
2.0 KiB
Swift

// RUN: %target-build-swift %s
// RUN: %target-swift-frontend -emit-sil -O -g %s | %FileCheck %s
// Issue #58660: Specifically-shaped differentiable functions yield "conflicting debug info for argument" assertion failure
// Ensure that proper location is preserved after sil-mem2reg location-less stores (created during inlining)
import _Differentiation
// May be a `struct` or `class`.
class MyState: Differentiable {
// All of these must be stored instance properties. There must be at least 7
// differentiable properties of any type.
var property1: Float = 0
var property2: Float = 0
var property3: Float = 0
var property4: Float = 0
var property5: Float = 0
var property6: Float = 0
var property7: Float = 0
}
struct MyModel: Differentiable {
// May be `var` or `let`, but must not be `@noDerivative`. Must be a stored
// instance property.
let property1 = MyState()
// Must be an instance property, either stored or computed.
var property2: Float {
// `get` must exist, and may add `mutating` attribute.
get { 0 }
// Cannot add `nonmutating` attribute to `set`.
set { }
}
// Must be an instance member. May be a function or computed property, but not
// a stored property.
var member3: Float {
// May not add `mutating` attribute.
get { 0 }
}
@differentiable(reverse)
mutating func member4() {
// CHECK-LABEL: // pullback of MyModel.member4()
// CHECK-NOT: debug_value %{{.*}} : $MyModel.TangentVector, var, name "self", argno 1, implicit, scope
// CHECK: bb1(%{{.*}} : $_AD__$s4main7MyModelV7member4yyF_bb1__PB__src_0_wrt_0):
// CHECK: debug_value %{{.*}} : $MyModel.TangentVector, var, name "self", argno 1, implicit, loc
// Must be a differentiable type.
var localVar: Float = 0
// Must be assigned from the value of `localVar`, not the value of anything else.
property2 = localVar
// `false` may instead be any expression that returns a `Bool`.
if false {
localVar = member3
}
}
}