Skip to content

Commit 84b33cc

Browse files
committed
Merge pull request #328 from manavgabhawala/master
Fixes [SR-78] swift compiler seg fault
2 parents 866e3cf + 9d7ec87 commit 84b33cc

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

lib/IRGen/GenType.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,17 +2031,19 @@ SILType irgen::getSingletonAggregateFieldType(IRGenModule &IGM,
20312031

20322032
// If there's only one stored property, we have the layout of its field.
20332033
auto allFields = structDecl->getStoredProperties();
2034+
20342035
auto field = allFields.begin();
2035-
if (std::next(field) == allFields.end())
2036+
if (!allFields.empty() && std::next(field) == allFields.end())
20362037
return t.getFieldType(*field, *IGM.SILMod);
20372038

20382039
return SILType();
20392040
}
20402041

20412042
if (auto enumDecl = t.getEnumOrBoundGenericEnum()) {
20422043
auto allCases = enumDecl->getAllElements();
2044+
20432045
auto theCase = allCases.begin();
2044-
if (std::next(theCase) == allCases.end()
2046+
if (!allCases.empty() && std::next(theCase) == allCases.end()
20452047
&& (*theCase)->hasArgumentType())
20462048
return t.getEnumElementType(*theCase, *IGM.SILMod);
20472049

test/IRGen/generic_enums.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-frontend -primary-file %s -emit-ir
2+
3+
struct Bar<A1, A2> {
4+
var a: A1
5+
var b: Foo<A1>
6+
}
7+
8+
enum Foo<A>{
9+
}

test/IRGen/generic_structs.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-swift-frontend -primary-file %s -emit-ir
2+
3+
struct A<T1, T2>
4+
{
5+
var b: T1
6+
var c: T2
7+
var d: B<T1, T2>
8+
}
9+
struct B<T1, T2>
10+
{
11+
var c: T1
12+
var d: T2
13+
}
14+
15+
struct C<T1>
16+
{}
17+
struct D<T2>
18+
{}
19+
20+
struct Foo<A1, A2>
21+
{
22+
var a: A1
23+
var b: Bar<A1, A2>
24+
}
25+
26+
struct Bar<A1, A2> {
27+
}

0 commit comments

Comments
 (0)