diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index ac8944f2c0623..916a87ba4fa15 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -4518,12 +4518,12 @@ void CallEmission::emitToUnmappedExplosionWithDirectTypedError( for (unsigned i = 0, e = structTy->getNumElements(); i < e; ++i) { llvm::Value *elt = values[combined.errorValueMapping[i]]; auto *nativeTy = structTy->getElementType(i); - elt = convertForAsyncDirect(IGF, elt, nativeTy, /*forExtraction*/ true); + elt = convertForDirectError(IGF, elt, nativeTy, /*forExtraction*/ true); errorExplosion.add(elt); } } else { auto *converted = - convertForAsyncDirect(IGF, values[combined.errorValueMapping[0]], + convertForDirectError(IGF, values[combined.errorValueMapping[0]], combined.combinedTy, /*forExtraction*/ true); errorExplosion.add(converted); } @@ -4541,12 +4541,12 @@ void CallEmission::emitToUnmappedExplosionWithDirectTypedError( dyn_cast(nativeSchema.getExpandedType(IGF.IGM))) { for (unsigned i = 0, e = structTy->getNumElements(); i < e; ++i) { auto *nativeTy = structTy->getElementType(i); - auto *converted = convertForAsyncDirect(IGF, values[i], nativeTy, + auto *converted = convertForDirectError(IGF, values[i], nativeTy, /*forExtraction*/ true); resultExplosion.add(converted); } } else { - auto *converted = convertForAsyncDirect( + auto *converted = convertForDirectError( IGF, values[0], combined.combinedTy, /*forExtraction*/ true); resultExplosion.add(converted); } @@ -5414,7 +5414,7 @@ llvm::Value* IRGenFunction::coerceValue(llvm::Value *value, llvm::Type *toTy, return loaded; } -llvm::Value *irgen::convertForAsyncDirect(IRGenFunction &IGF, +llvm::Value *irgen::convertForDirectError(IRGenFunction &IGF, llvm::Value *value, llvm::Type *toTy, bool forExtraction) { auto &Builder = IGF.Builder; @@ -5424,12 +5424,9 @@ llvm::Value *irgen::convertForAsyncDirect(IRGenFunction &IGF, if (toTy->isPointerTy()) { if (fromTy->isPointerTy()) return Builder.CreateBitCast(value, toTy); - if (fromTy == IGF.IGM.IntPtrTy) - return Builder.CreateIntToPtr(value, toTy); + return Builder.CreateIntToPtr(value, toTy); } else if (fromTy->isPointerTy()) { - if (toTy == IGF.IGM.IntPtrTy) { - return Builder.CreatePtrToInt(value, toTy); - } + return Builder.CreatePtrToInt(value, toTy); } if (forExtraction) { @@ -5887,12 +5884,12 @@ void IRGenFunction::emitScalarReturn(SILType returnResultType, for (unsigned i = 0, e = native.size(); i != e; ++i) { llvm::Value *elt = native.claimNext(); auto *nativeTy = structTy->getElementType(i); - elt = convertForAsyncDirect(*this, elt, nativeTy, + elt = convertForDirectError(*this, elt, nativeTy, /*forExtraction*/ false); nativeAgg = Builder.CreateInsertValue(nativeAgg, elt, i); } } else { - nativeAgg = convertForAsyncDirect(*this, native.claimNext(), combinedTy, + nativeAgg = convertForDirectError(*this, native.claimNext(), combinedTy, /*forExtraction*/ false); } } @@ -6224,7 +6221,7 @@ void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout, for (unsigned i = 0, e = result.size(); i != e; ++i) { llvm::Value *elt = result.claimNext(); auto *nativeTy = structTy->getElementType(i); - elt = convertForAsyncDirect(IGF, elt, nativeTy, + elt = convertForDirectError(IGF, elt, nativeTy, /*forExtraction*/ false); nativeAgg = IGF.Builder.CreateInsertValue(nativeAgg, elt, i); } @@ -6234,7 +6231,7 @@ void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout, nativeResultsStorage.push_back(out.claimNext()); } } else { - auto *converted = convertForAsyncDirect( + auto *converted = convertForDirectError( IGF, result.claimNext(), combinedTy, /*forExtraction*/ false); nativeResultsStorage.push_back(converted); } diff --git a/lib/IRGen/GenCall.h b/lib/IRGen/GenCall.h index e1e4a58f12da9..84b68041a0efd 100644 --- a/lib/IRGen/GenCall.h +++ b/lib/IRGen/GenCall.h @@ -274,8 +274,8 @@ namespace irgen { void forwardAsyncCallResult(IRGenFunction &IGF, CanSILFunctionType fnType, AsyncContextLayout &layout, llvm::CallInst *call); - /// Converts a value for async direct errors. - llvm::Value *convertForAsyncDirect(IRGenFunction &IGF, llvm::Value *value, + /// Converts a value for direct error return. + llvm::Value *convertForDirectError(IRGenFunction &IGF, llvm::Value *value, llvm::Type *toTy, bool forExtraction); } // end namespace irgen diff --git a/lib/IRGen/GenThunk.cpp b/lib/IRGen/GenThunk.cpp index a342911bde52e..12156a7fb1149 100644 --- a/lib/IRGen/GenThunk.cpp +++ b/lib/IRGen/GenThunk.cpp @@ -381,14 +381,14 @@ void IRGenThunk::emit() { for (unsigned i : combined.errorValueMapping) { llvm::Value *elt = nativeError.claimNext(); auto *nativeTy = structTy->getElementType(i); - elt = convertForAsyncDirect(IGF, elt, nativeTy, + elt = convertForDirectError(IGF, elt, nativeTy, /*forExtraction*/ false); expandedResult = IGF.Builder.CreateInsertValue(expandedResult, elt, i); } IGF.emitAllExtractValues(expandedResult, structTy, errorArgValues); } else if (!errorSchema.getExpandedType(IGM)->isVoidTy()) { - errorArgValues = convertForAsyncDirect(IGF, nativeError.claimNext(), + errorArgValues = convertForDirectError(IGF, nativeError.claimNext(), combined.combinedTy, /*forExtraction*/ false); } diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index 916667224479d..1e9334243eddc 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -4432,7 +4432,7 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) { for (unsigned i : combined.errorValueMapping) { llvm::Value *elt = nativeError.claimNext(); auto *nativeTy = structTy->getElementType(i); - elt = convertForAsyncDirect(*this, elt, nativeTy, + elt = convertForDirectError(*this, elt, nativeTy, /*forExtraction*/ false); expandedResult = Builder.CreateInsertValue(expandedResult, elt, i); } @@ -4443,7 +4443,7 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) { } } else if (!errorSchema.getExpandedType(IGM)->isVoidTy()) { out = - convertForAsyncDirect(*this, nativeError.claimNext(), + convertForDirectError(*this, nativeError.claimNext(), combined.combinedTy, /*forExtraction*/ false); } } else { diff --git a/test/IRGen/typed_throws_32_bit.swift b/test/IRGen/typed_throws_32_bit.swift new file mode 100644 index 0000000000000..e5927e0c8b756 --- /dev/null +++ b/test/IRGen/typed_throws_32_bit.swift @@ -0,0 +1,27 @@ +// RUN: %target-swift-frontend -emit-ir -primary-file %s + +// REQUIRES: CPU=arm64_32 || CPU=armv7k + +public class MyClass { + let x: Int64 + init(x: Int64) { + self.x = x + } +} + +public struct MyError: Error { + let x: MyClass +} + +@inline(never) +public func foo(f: () throws(MyError) -> Int64) throws(MyError) -> Int64 { + return try f() +} + +public func bar(f: () throws(MyError) -> Int64) -> Int64 { + do { + return try foo(f: f) + } catch { + return error.x.x + } +}