Skip to content

Commit d2e0582

Browse files
committed
Move workaround for swifterror miscompile earlier
Thank you, Arnold for noting this miscompile on x86!
1 parent cf73629 commit d2e0582

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3787,6 +3787,13 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) {
37873787

37883788
// If the error value is non-null, branch to the error destination.
37893789
auto hasError = Builder.CreateICmpNE(errorValue, nullError);
3790+
3791+
// Create a dummy use of 'errorValue' in the catch BB to workaround an
3792+
// LLVM miscompile that ends up taking the wrong branch if there are no
3793+
// uses of 'errorValue' in the catch block.
3794+
// FIXME: Remove this when the following radar is fixed: rdar://116636601
3795+
Builder.CreatePtrToInt(errorValue, IGM.IntPtrTy);
3796+
37903797
Builder.CreateCondBr(hasError,
37913798
typedErrorLoadBB ? typedErrorLoadBB : errorDest.bb,
37923799
normalDest.bb);
@@ -3806,12 +3813,6 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) {
38063813
} else {
38073814
Builder.emitBlock(typedErrorLoadBB);
38083815

3809-
// Create a dummy use of 'errorValue' in the catch BB to workaround an
3810-
// LLVM miscompile that ends up taking the wrong branch if there are no
3811-
// uses of 'errorValue' in the catch block.
3812-
// FIXME: Remove this when the following radar is fixed: rdar://116636601
3813-
Builder.CreatePtrToInt(errorValue, IGM.IntPtrTy);
3814-
38153816
auto &ti = cast<LoadableTypeInfo>(IGM.getTypeInfo(errorType));
38163817
Explosion errorValue;
38173818
ti.loadAsTake(*this, getCalleeTypedErrorResultSlot(errorType), errorValue);

test/IRGen/errors.sil

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ entry(%0 : $AnyObject):
8383
// CHECK-native-NEXT: [[RESULT:%.*]] = call swiftcc ptr @try_apply_helper(ptr %0, ptr swiftself undef, ptr noalias nocapture [[SWIFTERROR]]{{( )?}}dereferenceable({{.}}) [[ERRORSLOT]])
8484
// CHECK-NEXT: [[ERR:%.*]] = load ptr, ptr [[ERRORSLOT]], align
8585
// CHECK-NEXT: [[T0:%.*]] = icmp ne ptr [[ERR]], null
86+
// CHECK-NEXT: ptrtoint ptr [[ERR]] to i
8687
// CHECK-NEXT: br i1 [[T0]],
8788
%1 = function_ref @try_apply_helper : $@convention(thin) (@owned AnyObject) -> (@owned AnyObject, @error Error)
8889
try_apply %1(%0) : $@convention(thin) (@owned AnyObject) -> (@owned AnyObject, @error Error),

test/IRGen/unmanaged_objc_throw_func.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ import Foundation
2424
// CHECK-NEXT: call void @llvm.objc.release(ptr %[[T4]])
2525
// CHECK-NEXT: ret ptr %[[T4]]
2626
let arr = [1] as CFArray
27-
return Unmanaged.passUnretained(arr)
28-
}
27+
return Unmanaged.passUnretained(arr)
28+
}
2929
}
3030

3131
// CHECK: %[[T0:.+]] = call swiftcc ptr @"$s25unmanaged_objc_throw_func1CC22returnUnmanagedCFArrays0F0VySo0G3RefaGyKF"
3232
// CHECK-NEXT: %[[T2:.+]] = load ptr, ptr %swifterror, align {{[0-9]+}}
3333
// CHECK-NEXT: %[[T3:.+]] = icmp ne ptr %[[T2]], null
34+
// CHECK-NEXT: ptrtoint ptr %[[T2]] to i
3435
// CHECK-NEXT: br i1 %[[T3]], label %[[L1:.+]], label %[[L2:.+]]
3536

3637
// CHECK: [[L2]]: ; preds = %entry

0 commit comments

Comments
 (0)