Skip to content

Commit e3a27a1

Browse files
committed
IRGen: Allocate an address for the result of zero sized typed error results
rdar://118657904
1 parent ad68322 commit e3a27a1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4751,6 +4751,13 @@ Address IRGenFunction::createErrorResultSlot(SILType errorType, bool isAsync,
47514751
auto errorAlignment = isTypedError ? IGM.getPointerAlignment() :
47524752
cast<FixedTypeInfo>(getTypeInfo(errorType)).getFixedAlignment();
47534753

4754+
// Pass an address for zero sized types.
4755+
if (!isTypedError && !setSwiftErrorFlag &&
4756+
cast<FixedTypeInfo>(getTypeInfo(errorType)).getFixedSize() == Size(0)) {
4757+
errorStorageType = IGM.Int8PtrTy;
4758+
errorAlignment = IGM.getPointerAlignment();
4759+
}
4760+
47544761
// Create the alloca. We don't use allocateStack because we're
47554762
// not allocating this in stack order.
47564763
auto addr = createAlloca(errorStorageType,

test/IRGen/typed_throws.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,15 @@ func reabstractAsConcreteThrowing() throws -> Int {
6666
// CHECK-LABEL: define {{.*}} swiftcc void @"$sSi12typed_throws10MyBigErrorOIgdzo_SiACIegrzr_TR"(ptr noalias nocapture sret(%TSi) %0, ptr %1, ptr %2, ptr swiftself %3, ptr noalias nocapture swifterror dereferenceable(8) %4, ptr %5)
6767
// CHECK: call swiftcc {{i32|i64}} %1
6868
// CHECK: br i1 %8, label %typed.error.load, label %10
69+
70+
71+
struct S : Error { }
72+
73+
func callee() throws (S) {
74+
throw S()
75+
}
76+
77+
// This used to crash at compile time.
78+
func testit() throws (S) {
79+
try callee()
80+
}

0 commit comments

Comments
 (0)