Files
swift-mirror/test/SILOptimizer/specialization_and_resilience.swift
Erik Eckstein 9e43f493f3 GenericSpecializer: use an alternative mangling if the function has re-abstracted resilient type parameters.
If the specialized function has a re-abstracted (= converted from indirect to direct) resilient argument or return types, use an alternative mangling: "TB" instead of "Tg".
Resilient parameters/returns can be converted from indirect to direct if the specialization is created within the type's resilience domain, i.e. in its module (where the type is loadable).
In this case we need to generate a different mangled name for the specialized function to distinguish it from specializations in other modules, which cannot re-abstract this resilient type.

This fixes a miscompile resulting from ODR-linking specializations from different modules, which in fact have different function signatures.

https://bugs.swift.org/browse/SR-13900
rdar://71914016
2020-12-07 17:23:46 +01:00

20 lines
701 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift -wmo -O -enable-library-evolution %S/Inputs/specialization_and_resilience_module.swift -DMODULE -parse-as-library -emit-module -emit-module-path=%t/Test.swiftmodule -module-name=Test -c -o %t/module.o
// RUN: %target-build-swift -wmo -O %s -I%t -module-name=Main -c -o %t/main.o
// RUN: %target-build-swift %t/main.o %t/module.o -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: executable_test
import Test
// CHECK: Mystruct(x: 100)
testParam(Mystruct(100))
// CHECK: Mystruct(x: 101)
print(testReturn([Mystruct(101)]))
// CHECK: Mystruct(x: 27)
// CHECK: Mystruct(x: 28)
otherFunc()