Skip to content

Commit c22f010

Browse files
authored
Merge pull request swiftlang#32943 from slavapestov/fix-same-type-concrete-crash-5.3
GSB: Fix use-after-free error when vending ResolvedType [5.3]
2 parents 7c71491 + b16901a commit c22f010

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

lib/AST/GenericSignatureBuilderImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GenericSignatureBuilder::ResolvedType {
2424
public:
2525
/// A specific resolved potential archetype.
2626
ResolvedType(PotentialArchetype *pa)
27-
: type(pa), equivClass(pa->getEquivalenceClassIfPresent()) { }
27+
: type(pa), equivClass(nullptr) { }
2828

2929
/// A resolved type within the given equivalence class.
3030
ResolvedType(Type type, EquivalenceClass *equivClass)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-frontend -emit-ir %s
2+
3+
public protocol P1 {
4+
associatedtype Value
5+
}
6+
7+
public protocol P2 {
8+
associatedtype Value
9+
}
10+
11+
public class Class2<V> : P2 {
12+
public typealias Value = V
13+
}
14+
15+
public class Superclass<T1, T2> where T1 : P1, T2 : P2, T2.Value == T1.Value {
16+
}
17+
18+
public class Subclass<T1, T2> : Superclass<T1, T2> where T1 : P1, T2 : Class2<T1.Value> {
19+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// RUN: %target-swift-frontend -emit-ir %s
2+
3+
public protocol DefaultInitializable {
4+
init()
5+
}
6+
7+
public protocol AdjacencyEdge_ {
8+
associatedtype VertexID: Equatable
9+
associatedtype Properties
10+
11+
var destination: VertexID { get set }
12+
var properties: Properties { get set }
13+
}
14+
15+
public struct AdjacencyEdge<VertexID: Equatable, Properties>: AdjacencyEdge_ {
16+
public var destination: VertexID
17+
public var properties: Properties
18+
}
19+
20+
public protocol AdjacencyVertex_ {
21+
associatedtype Edges: Collection where Edges.Element: AdjacencyEdge_
22+
associatedtype Properties
23+
24+
var edges: Edges { get set }
25+
var properties: Properties { get set }
26+
}
27+
28+
public struct AdjacencyVertex<Edges: Collection, Properties> : AdjacencyVertex_
29+
where Edges.Element: AdjacencyEdge_
30+
{
31+
public var edges: Edges
32+
public var properties: Properties
33+
}
34+
35+
public protocol BinaryFunction {
36+
associatedtype Parameter0
37+
associatedtype Parameter1
38+
associatedtype Result
39+
40+
func callAsFunction(_: Parameter0, _: Parameter1) -> Result
41+
}
42+
43+
public struct GeneralAdjacencyList<
44+
Spine: Collection, VertexIDToIndex: BinaryFunction
45+
>
46+
where Spine.Element : AdjacencyVertex_,
47+
VertexIDToIndex.Parameter0 == Spine,
48+
VertexIDToIndex.Parameter1 == Spine.Element.Edges.Element.VertexID,
49+
VertexIDToIndex.Result == Spine.Index
50+
{
51+
public let vertexIDToIndex: VertexIDToIndex
52+
public var spine: Spine
53+
}
54+
55+
public struct IdentityVertexIDToIndex<Spine: Collection>: BinaryFunction
56+
where Spine.Element : AdjacencyVertex_,
57+
Spine.Element.Edges.Element.VertexID == Spine.Index
58+
{
59+
public func callAsFunction(_: Spine, _ id: Spine.Index) -> Spine.Index {
60+
return id
61+
}
62+
}
63+
64+
public extension GeneralAdjacencyList {
65+
typealias VertexID = VertexIDToIndex.Parameter1
66+
typealias VertexProperties = Spine.Element.Properties
67+
typealias EdgeProperties = Spine.Element.Edges.Element.Properties
68+
69+
struct EdgeID: Equatable {
70+
/// The source vertex.
71+
let source: VertexIDToIndex.Parameter1
72+
/// The position of the edge in `source`'s list of edges.
73+
let targetIndex: Spine.Index
74+
}
75+
}
76+
77+
public extension GeneralAdjacencyList
78+
where VertexIDToIndex == IdentityVertexIDToIndex<Spine>,
79+
Spine: RangeReplaceableCollection,
80+
Spine.Element.Edges: RangeReplaceableCollection
81+
& BidirectionalCollection // Because https://bugs.swift.org/browse/SR-12810
82+
{
83+
func addVertex(storing properties: VertexProperties) -> VertexID {
84+
return spine.indices.first!
85+
}
86+
}
87+

0 commit comments

Comments
 (0)