Skip to content

Commit

Permalink
IRGen: Scalar type layouts need to profile the SIL type
Browse files Browse the repository at this point in the history
It might contain archetypes whose type metadata is required.

rdar://68972976
SR-13555
  • Loading branch information
aschwaighofer committed Sep 22, 2020
1 parent ec72db1 commit 383d47f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/IRGen/TypeLayout.cpp
Expand Up @@ -596,12 +596,14 @@ void ScalarTypeLayoutEntry::computeProperties() {
}

void ScalarTypeLayoutEntry::Profile(llvm::FoldingSetNodeID &id) const {
ScalarTypeLayoutEntry::Profile(id, typeInfo);
ScalarTypeLayoutEntry::Profile(id, typeInfo, representative);
}

void ScalarTypeLayoutEntry::Profile(llvm::FoldingSetNodeID &id,
const TypeInfo &ti) {
const TypeInfo &ti,
SILType ty) {
id.AddPointer(&ti);
id.AddPointer(ty.getASTType().getPointer());
}

ScalarTypeLayoutEntry::~ScalarTypeLayoutEntry() {}
Expand Down Expand Up @@ -2083,7 +2085,7 @@ TypeLayoutCache::getOrCreateScalarEntry(const TypeInfo &ti,
SILType representative) {
assert(ti.isFixedSize());
llvm::FoldingSetNodeID id;
ScalarTypeLayoutEntry::Profile(id, ti);
ScalarTypeLayoutEntry::Profile(id, ti, representative);
// Do we already have an entry.
void *insertPos;
if (auto *entry = scalarEntries.FindNodeOrInsertPos(id, insertPos)) {
Expand Down
4 changes: 3 additions & 1 deletion lib/IRGen/TypeLayout.h
Expand Up @@ -124,6 +124,7 @@ class ScalarTypeLayoutEntry : public TypeLayoutEntry,
public:
const TypeInfo &typeInfo;
SILType representative;

ScalarTypeLayoutEntry(const TypeInfo &ti, SILType representative)
: TypeLayoutEntry(TypeLayoutEntryKind::Scalar), typeInfo(ti),
representative(representative) {}
Expand All @@ -134,7 +135,8 @@ class ScalarTypeLayoutEntry : public TypeLayoutEntry,

// Support for FoldingSet.
void Profile(llvm::FoldingSetNodeID &id) const;
static void Profile(llvm::FoldingSetNodeID &ID, const TypeInfo &ti);
static void Profile(llvm::FoldingSetNodeID &ID, const TypeInfo &ti,
SILType ty);

llvm::Value *alignmentMask(IRGenFunction &IGF) const override;
llvm::Value *size(IRGenFunction &IGF) const override;
Expand Down
19 changes: 19 additions & 0 deletions test/IRGen/typelayout_based_value_witness.swift
Expand Up @@ -87,3 +87,22 @@ public struct A<T> {
// OPT: tail call void [[DESTROY]](%swift.opaque* noalias [[ADDR_T4]], %swift.type* [[T]])
// OPT: ret void
// CHECK: }

// Let's not crash on the following example.
public protocol P {}

public class Ref<T: P> {}

public enum E1<R: P> {
case first(R)
case second(S<R>)
}

public struct S<T: P> {
public let f: E2<T>? = nil
}

public enum E2<T: P> {
case first(Ref<T>)
case second(String)
}

0 comments on commit 383d47f

Please sign in to comment.