Skip to content

Commit 361c477

Browse files
Merge pull request #34024 from aschwaighofer/irgen_type_layout_profile_sil_type
IRGen: Scalar type layouts need to profile the SIL type
2 parents 67af4ce + 383d47f commit 361c477

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lib/IRGen/TypeLayout.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,14 @@ void ScalarTypeLayoutEntry::computeProperties() {
596596
}
597597

598598
void ScalarTypeLayoutEntry::Profile(llvm::FoldingSetNodeID &id) const {
599-
ScalarTypeLayoutEntry::Profile(id, typeInfo);
599+
ScalarTypeLayoutEntry::Profile(id, typeInfo, representative);
600600
}
601601

602602
void ScalarTypeLayoutEntry::Profile(llvm::FoldingSetNodeID &id,
603-
const TypeInfo &ti) {
603+
const TypeInfo &ti,
604+
SILType ty) {
604605
id.AddPointer(&ti);
606+
id.AddPointer(ty.getASTType().getPointer());
605607
}
606608

607609
ScalarTypeLayoutEntry::~ScalarTypeLayoutEntry() {}
@@ -2083,7 +2085,7 @@ TypeLayoutCache::getOrCreateScalarEntry(const TypeInfo &ti,
20832085
SILType representative) {
20842086
assert(ti.isFixedSize());
20852087
llvm::FoldingSetNodeID id;
2086-
ScalarTypeLayoutEntry::Profile(id, ti);
2088+
ScalarTypeLayoutEntry::Profile(id, ti, representative);
20872089
// Do we already have an entry.
20882090
void *insertPos;
20892091
if (auto *entry = scalarEntries.FindNodeOrInsertPos(id, insertPos)) {

lib/IRGen/TypeLayout.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class ScalarTypeLayoutEntry : public TypeLayoutEntry,
124124
public:
125125
const TypeInfo &typeInfo;
126126
SILType representative;
127+
127128
ScalarTypeLayoutEntry(const TypeInfo &ti, SILType representative)
128129
: TypeLayoutEntry(TypeLayoutEntryKind::Scalar), typeInfo(ti),
129130
representative(representative) {}
@@ -134,7 +135,8 @@ class ScalarTypeLayoutEntry : public TypeLayoutEntry,
134135

135136
// Support for FoldingSet.
136137
void Profile(llvm::FoldingSetNodeID &id) const;
137-
static void Profile(llvm::FoldingSetNodeID &ID, const TypeInfo &ti);
138+
static void Profile(llvm::FoldingSetNodeID &ID, const TypeInfo &ti,
139+
SILType ty);
138140

139141
llvm::Value *alignmentMask(IRGenFunction &IGF) const override;
140142
llvm::Value *size(IRGenFunction &IGF) const override;

test/IRGen/typelayout_based_value_witness.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,22 @@ public struct A<T> {
8787
// OPT: tail call void [[DESTROY]](%swift.opaque* noalias [[ADDR_T4]], %swift.type* [[T]])
8888
// OPT: ret void
8989
// CHECK: }
90+
91+
// Let's not crash on the following example.
92+
public protocol P {}
93+
94+
public class Ref<T: P> {}
95+
96+
public enum E1<R: P> {
97+
case first(R)
98+
case second(S<R>)
99+
}
100+
101+
public struct S<T: P> {
102+
public let f: E2<T>? = nil
103+
}
104+
105+
public enum E2<T: P> {
106+
case first(Ref<T>)
107+
case second(String)
108+
}

0 commit comments

Comments
 (0)