|
| 1 | +// RUN: %target-swift-frontend -c %s -g -O -parse-stdlib -parse-as-library -module-name Swift |
| 2 | + |
| 3 | +// TF-597: Exact minimal reproducer for IRGenDebugInfo crash. |
| 4 | +// Crash occurred only with `-g` and `-O`. |
| 5 | +// |
| 6 | +// ``` |
| 7 | +// Assertion failed: (OffsetInBits + SizeInBits <= getSizeInBits(Var) && "pars > totum"), |
| 8 | +// function emitVariableDeclaration, file swift/lib/IRGen/IRGenDebugInfo.cpp, line 2216. |
| 9 | +// Stack dump: |
| 10 | +// 1. Swift version 5.1-dev (LLVM 200186e28b, Swift c09c14dec5) |
| 11 | +// 2. While emitting IR SIL function "@$ss8pullback2at2inyx_q_xXFts14DifferentiableRzsADR_r0_lF". |
| 12 | +// for 'pullback(at:in:)' (at swift/test/AutoDiff/differentiable_func_debuginfo.swift:21:8) |
| 13 | +// ``` |
| 14 | +// |
| 15 | +// The crash was because `IRGenDebugInfoImpl::getOrCreateType` computes |
| 16 | +// `llvm::DIType` type debug info by demangling type names. |
| 17 | +// |
| 18 | +// Since `@differentiable` and `@differentiable(linear)` function types did |
| 19 | +// not have mangling support, `getOrCreateType` computed a regular `(A) -> B` |
| 20 | +// function type instead of a `@differentiable (A) -> B` function type, leading |
| 21 | +// to a type size inconsistency. |
| 22 | +// |
| 23 | +// Conclusion: mangling coverage is important. |
| 24 | + |
| 25 | +// Minimal dummy compiler-known `Differentiable` protocol. |
| 26 | +public protocol Differentiable { |
| 27 | + associatedtype TangentVector |
| 28 | +} |
| 29 | + |
| 30 | +// This declaration is necessary to reproduce the crash for some reason. |
| 31 | +public func blackHole<T, U>(_: (T) -> U) {} |
| 32 | + |
| 33 | +public func pullback<T, R>( |
| 34 | + at x: T, in tf597ProblematicVarDecl: @differentiable (T) -> R |
| 35 | +) { |
| 36 | + let _ = Builtin.autodiffApply_vjp(tf597ProblematicVarDecl, x) |
| 37 | +} |
0 commit comments