Skip to content

IRGen: Allocate an address for the result of zero sized typed error results #70067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4751,6 +4751,13 @@ Address IRGenFunction::createErrorResultSlot(SILType errorType, bool isAsync,
auto errorAlignment = isTypedError ? IGM.getPointerAlignment() :
cast<FixedTypeInfo>(getTypeInfo(errorType)).getFixedAlignment();

// Pass an address for zero sized types.
if (!isTypedError && !setSwiftErrorFlag &&
cast<FixedTypeInfo>(getTypeInfo(errorType)).getFixedSize() == Size(0)) {
errorStorageType = IGM.Int8PtrTy;
errorAlignment = IGM.getPointerAlignment();
}

// Create the alloca. We don't use allocateStack because we're
// not allocating this in stack order.
auto addr = createAlloca(errorStorageType,
Expand Down
12 changes: 12 additions & 0 deletions test/IRGen/typed_throws.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,15 @@ func reabstractAsConcreteThrowing() throws -> Int {
// 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)
// CHECK: call swiftcc {{i32|i64}} %1
// CHECK: br i1 %8, label %typed.error.load, label %10


struct S : Error { }

func callee() throws (S) {
throw S()
}

// This used to crash at compile time.
func testit() throws (S) {
try callee()
}