Skip to content

Commit 11a55de

Browse files
committed
[IRGen] Apply int to ptr conversion for direct error returns if necessary
rdar://131494255 When merging a ptr into an int value for direct error return, we have to properly convert it back to a pointer at the callsite
1 parent 25929b3 commit 11a55de

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
@@ -127,3 +127,16 @@ func mayThrow(x: Bool, y: AnyObject) throws(MyError) -> (Float, Int32, Float) {
127127
}
128128
return (3.0, 4, 5.0)
129129
}
130+
131+
// CHECK: define hidden swiftcc { i64, i64 } @"$s12typed_throws25directErrorMergePtrAndInt1x1yyXl_SitSb_yXltAA05SmallD0VYKF"
132+
// CHECK: [[RES:%.*]] = call swiftcc { i64, i64 } @"$s12typed_throws25directErrorMergePtrAndInt1x1yyXl_SitSb_yXltAA05SmallD0VYKF"
133+
// CHECK: [[R0:%.*]] = extractvalue { i64, i64 } [[RES]], 0
134+
// CHECK: inttoptr i64 [[R0]] to ptr
135+
// CHECK: }
136+
func directErrorMergePtrAndInt(x: Bool, y: AnyObject) throws(SmallError) -> (AnyObject, Int) {
137+
guard x else {
138+
throw SmallError(x: 1)
139+
}
140+
141+
return try directErrorMergePtrAndInt(x: !x, y: y)
142+
}

0 commit comments

Comments
 (0)