Skip to content

SIL Printer: Fix crash when @_specialize attribute applied to a declaration #16587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/SIL/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3017,9 +3017,12 @@ void SILSpecializeAttr::print(llvm::raw_ostream &OS) const {
SILFunction *F = getFunction();
assert(F);
auto GenericEnv = F->getGenericEnvironment();
assert(GenericEnv);
interleave(getRequirements(),
[&](Requirement req) {
if (!GenericEnv) {
req.print(OS, SubPrinter);
return;
}
// Use GenericEnvironment to produce user-friendly
// names instead of something like t_0_0.
auto FirstTy = GenericEnv->getSugaredType(req.getFirstType());
Expand Down
3 changes: 0 additions & 3 deletions test/Sema/fixed_ambiguities/rdar35623181.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// RUN: %target-swift-frontend -emit-sil -verify %s | %FileCheck %s

// XFAIL: *
// ^ SR-7673

extension Sequence where Element == String {
func record() -> String {
// 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
Expand Down
12 changes: 6 additions & 6 deletions test/Serialization/serialize_attr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,23 @@

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

// @_optimize
// -----------------------------------------------------------------------------

//CHECK-DAG: @_optimize(none) func test_onone()
@inlinable
@usableFromInline
@_optimize(none)
func test_onone() -> Int { return 5}

//CHECK-DAG: @_optimize(speed) func test_ospeed()
@inlinable
@usableFromInline
@_optimize(speed)
func test_ospeed() -> Int { return 5}

//CHECK-DAG: @_optimize(size) func test_osize()
@inlinable
@usableFromInline
@_optimize(size)
func test_osize() -> Int { return 5}

Expand All @@ -42,9 +38,14 @@ func test_osize() -> Int { return 5}
// CHECK-DAG: @_specialize(exported: false, kind: full, where T == Int, U == Float)
// CHECK-DAG: func specializeThis<T, U>(_ t: T, u: U)
@inlinable
@_specialize(where T == Int, U == Float)
func specializeThis<T, U>(_ t: T, u: U) {
specializeThat(t, u: u)
}

@usableFromInline
@_specialize(where T == Int, U == Float)
func specializeThis<T, U>(_ t: T, u: U) {}
func specializeThat<T, U>(_ t: T, u: U) {}

public protocol PP {
associatedtype PElt
Expand All @@ -71,7 +72,6 @@ public struct GG<T : PP> {}
// CHECK-DAG: @inline(never) func foo<U>(_ u: U, g: GG<T>) -> (U, GG<T>) where U : QQ
public class CC<T : PP> {
@inlinable
@usableFromInline
@inline(never)
@_specialize(where T==RR, U==SS)
func foo<U : QQ>(_ u: U, g: GG<T>) -> (U, GG<T>) {
Expand Down