Skip to content

Commit 32af2f6

Browse files
authored
Merge pull request swiftlang#75149 from drexin/wip-ptr-cast-tt
[IRGen] Apply int to ptr conversion for direct error returns if neces…
2 parents d84a919 + 11a55de commit 32af2f6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/IRGen/GenCall.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -4405,6 +4405,9 @@ void CallEmission::emitToUnmappedExplosionWithDirectTypedError(
44054405
auto *eltTy = elt->getType();
44064406
if (nativeTy->isIntOrPtrTy() && eltTy->isIntOrPtrTy() &&
44074407
nativeTy->getPrimitiveSizeInBits() != eltTy->getPrimitiveSizeInBits()) {
4408+
if (nativeTy->isPointerTy() && eltTy == IGF.IGM.IntPtrTy) {
4409+
return IGF.Builder.CreateIntToPtr(elt, nativeTy);
4410+
}
44084411
return IGF.Builder.CreateTruncOrBitCast(elt, nativeTy);
44094412
}
44104413
return elt;

test/IRGen/typed_throws.swift

+13
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,16 @@ func mayThrow(x: Bool, y: AnyObject) throws(MyError) -> (Float, Int32, Float) {
131131
}
132132
return (3.0, 4, 5.0)
133133
}
134+
135+
// CHECK: define hidden swiftcc { i64, i64 } @"$s12typed_throws25directErrorMergePtrAndInt1x1yyXl_SitSb_yXltAA05SmallD0VYKF"
136+
// CHECK: [[RES:%.*]] = call swiftcc { i64, i64 } @"$s12typed_throws25directErrorMergePtrAndInt1x1yyXl_SitSb_yXltAA05SmallD0VYKF"
137+
// CHECK: [[R0:%.*]] = extractvalue { i64, i64 } [[RES]], 0
138+
// CHECK: inttoptr i64 [[R0]] to ptr
139+
// CHECK: }
140+
func directErrorMergePtrAndInt(x: Bool, y: AnyObject) throws(SmallError) -> (AnyObject, Int) {
141+
guard x else {
142+
throw SmallError(x: 1)
143+
}
144+
145+
return try directErrorMergePtrAndInt(x: !x, y: y)
146+
}

0 commit comments

Comments
 (0)