swift
2cc9a2f3 - [SILOptimizer] Test ConstantCapturePropagation ODR violation with generic closures (#87916)

Commit
5 days ago
[SILOptimizer] Test ConstantCapturePropagation ODR violation with generic closures (#87916) ## Summary This PR fixes the ODR violation detailed in https://github.com/swiftlang/swift/issues/87917 ## Impl When specializeClosure determines the specialized closure remains generic (`isGeneric == true`), clone the body without applying type substitutions, and use `partial_apply` with the substitution map at the call site instead of `thin_to_thick_function`. The body stays generic with type parameters like `$*Optional<Self>`, which is correct since all callers share the same shared symbol and apply their own concrete types through the substitution map on the `partial_apply`. ## Tests Add SIL and executable tests demonstrating that ConstantCapturePropagation produces an ODR violation when specializing generic closures with different concrete type substitutions but the same constant captures. The SIL test provides a minimal reproducer: two callers instantiate the same generic closure with UInt8 and Int respectively, both capturing constant `radix=10`. With `-enable-sil-verify-all`, the verifier catches the type mismatch in the specialized function body. The executable test exercises the real-world scenario through `FixedWidthInteger.init?(_:radix:)`, where the miscompile causes Int and `Int32` parsing to return garbage values because the closure body was baked with `UInt8` type metadata. Fixes: https://github.com/swiftlang/swift/issues/87917 [Assisted-by](https://t.ly/Dkjjk): [Claude Opus 4.6](https://www.anthropic.com/news/claude-opus-4-6) cc @drodriguez @kyulee-com
Author
Parents
Loading