Skip to content

Commit 2c684e5

Browse files
authored
Merge pull request #16587 from slavapestov/fix-sil-printer-crash
SIL Printer: Fix crash when @_specialize attribute applied to a declaration
2 parents 254f2f5 + 7ed2f8c commit 2c684e5

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

lib/SIL/SILPrinter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3017,9 +3017,12 @@ void SILSpecializeAttr::print(llvm::raw_ostream &OS) const {
30173017
SILFunction *F = getFunction();
30183018
assert(F);
30193019
auto GenericEnv = F->getGenericEnvironment();
3020-
assert(GenericEnv);
30213020
interleave(getRequirements(),
30223021
[&](Requirement req) {
3022+
if (!GenericEnv) {
3023+
req.print(OS, SubPrinter);
3024+
return;
3025+
}
30233026
// Use GenericEnvironment to produce user-friendly
30243027
// names instead of something like t_0_0.
30253028
auto FirstTy = GenericEnv->getSugaredType(req.getFirstType());

test/Sema/fixed_ambiguities/rdar35623181.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// RUN: %target-swift-frontend -emit-sil -verify %s | %FileCheck %s
22

3-
// XFAIL: *
4-
// ^ SR-7673
5-
63
extension Sequence where Element == String {
74
func record() -> String {
85
// CHECK: function_ref @$Ss20LazySequenceProtocolPsE3mapys0a3MapB0Vy8ElementsQzqd__Gqd__7ElementQzclF : $@convention(method) <τ_0_0 where τ_0_0 : LazySequenceProtocol><τ_1_0> (@guaranteed @callee_guaranteed (@in_guaranteed τ_0_0.Element) -> @out τ_1_0, @in_guaranteed τ_0_0) -> @out LazyMapSequence<τ_0_0.Elements, τ_1_0

test/Serialization/serialize_attr.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,23 @@
1111

1212
//CHECK-DAG: @_semantics("crazy") func foo()
1313
@inlinable
14-
@usableFromInline
1514
@_semantics("crazy") func foo() -> Int { return 5}
1615

1716
// @_optimize
1817
// -----------------------------------------------------------------------------
1918

2019
//CHECK-DAG: @_optimize(none) func test_onone()
2120
@inlinable
22-
@usableFromInline
2321
@_optimize(none)
2422
func test_onone() -> Int { return 5}
2523

2624
//CHECK-DAG: @_optimize(speed) func test_ospeed()
2725
@inlinable
28-
@usableFromInline
2926
@_optimize(speed)
3027
func test_ospeed() -> Int { return 5}
3128

3229
//CHECK-DAG: @_optimize(size) func test_osize()
3330
@inlinable
34-
@usableFromInline
3531
@_optimize(size)
3632
func test_osize() -> Int { return 5}
3733

@@ -42,9 +38,14 @@ func test_osize() -> Int { return 5}
4238
// CHECK-DAG: @_specialize(exported: false, kind: full, where T == Int, U == Float)
4339
// CHECK-DAG: func specializeThis<T, U>(_ t: T, u: U)
4440
@inlinable
41+
@_specialize(where T == Int, U == Float)
42+
func specializeThis<T, U>(_ t: T, u: U) {
43+
specializeThat(t, u: u)
44+
}
45+
4546
@usableFromInline
4647
@_specialize(where T == Int, U == Float)
47-
func specializeThis<T, U>(_ t: T, u: U) {}
48+
func specializeThat<T, U>(_ t: T, u: U) {}
4849

4950
public protocol PP {
5051
associatedtype PElt
@@ -71,7 +72,6 @@ public struct GG<T : PP> {}
7172
// CHECK-DAG: @inline(never) func foo<U>(_ u: U, g: GG<T>) -> (U, GG<T>) where U : QQ
7273
public class CC<T : PP> {
7374
@inlinable
74-
@usableFromInline
7575
@inline(never)
7676
@_specialize(where T==RR, U==SS)
7777
func foo<U : QQ>(_ u: U, g: GG<T>) -> (U, GG<T>) {

0 commit comments

Comments
 (0)