Files
swift-mirror/test/IRGen/errors.sil
Manman Ren e94aae06da [Function Attribute] add target-cpu and target-features sets if they're non-null.
All llvm::Functions created during IRGen will have target-cpu and target-features
attributes if they are non-null.

Update testing cases to expect the attribute in function definition.
Add testing case function-target-features.swift to verify target-cpu and
target-features.

rdar://20772331


Swift SVN r28186
2015-05-05 23:19:48 +00:00

86 lines
3.3 KiB
Plaintext

// RUN: %target-swift-frontend %s -emit-ir | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
sil_stage canonical
import Builtin
import Swift
sil @create_error : $@convention(thin) () -> @owned _ErrorType {
entry:
unreachable
}
// CHECK: define void @throws(%swift.refcounted*, %swift.error**) {{.*}} {
sil @throws : $@convention(thin) () -> @error _ErrorType {
// CHECK: [[T0:%.*]] = call %swift.error* @create_error()
%0 = function_ref @create_error : $@convention(thin) () -> @owned _ErrorType
%1 = apply %0() : $@convention(thin) () -> @owned _ErrorType
// CHECK-NEXT: call void @swift_willThrow
// CHECK-NEXT: store %swift.error* [[T0]], %swift.error** %1,
// CHECK-NEXT: ret void
builtin "willThrow"(%1 : $_ErrorType) : $()
throw %1 : $_ErrorType
}
// CHECK: define void @doesnt_throw(%swift.refcounted*, %swift.error**) {{.*}} {
sil @doesnt_throw : $@convention(thin) () -> @error _ErrorType {
// We don't have to do anything here because the caller always
// zeroes the error slot before a call.
// CHECK-NEXT: entry:
// CHECK-NEXT: ret void
%0 = tuple ()
return %0 : $()
}
sil @try_apply_helper : $@convention(thin) (@owned AnyObject) -> (@owned AnyObject, @error _ErrorType)
// CHECK: define void @try_apply(%objc_object*)
sil @try_apply : $@convention(thin) (@owned AnyObject) -> () {
entry(%0 : $AnyObject):
// CHECK: [[ERRORSLOT:%.*]] = alloca %swift.error*, align
// CHECK-NEXT: store %swift.error* null, %swift.error** [[ERRORSLOT]], align
// CHECK-NEXT: [[RESULT:%.*]] = call %objc_object* @try_apply_helper(%objc_object* %0, %swift.refcounted* undef, %swift.error** nocapture [[ERRORSLOT]])
// CHECK-NEXT: [[ERR:%.*]] = load %swift.error*, %swift.error** [[ERRORSLOT]], align
// CHECK-NEXT: store %swift.error* null, %swift.error** [[ERRORSLOT]], align
// CHECK-NEXT: [[T0:%.*]] = icmp ne %swift.error* [[ERR]], null
// CHECK-NEXT: br i1 [[T0]],
%1 = function_ref @try_apply_helper : $@convention(thin) (@owned AnyObject) -> (@owned AnyObject, @error _ErrorType)
try_apply %1(%0) : $@convention(thin) (@owned AnyObject) -> (@owned AnyObject, @error _ErrorType),
normal bb1, error bb2
// CHECK: [[T0:%.*]] = phi %objc_object* [ [[RESULT]],
// CHECK-objc-NEXT: call void bitcast (void (%swift.refcounted*)* @swift_unknownRelease to void (%objc_object*)*)(%objc_object* [[T0]])
// CHECK-native-NEXT: call void bitcast (void (%swift.refcounted*)* @swift_release to void (%objc_object*)*)(%objc_object* [[T0]])
// CHECK-NEXT: br label [[CONT:%[0-9]+]]
bb1(%2 : $AnyObject):
strong_release %2 : $AnyObject
br bb3
// CHECK: [[T0:%.*]] = phi %swift.error* [ [[ERR]],
// CHECK-NEXT: call void @swift_errorRelease(%swift.error* [[T0]])
// CHECK-NEXT: br label [[CONT]]
bb2(%3 : $_ErrorType):
release_value %3 : $_ErrorType
br bb3
bb3:
%4 = tuple ()
return %4 : $()
}
enum ColorError : _ErrorType {
case Red, Green, Blue
}
// CHECK-LABEL: TestCallToWillThrowCallBack
// CHECK: call void @swift_willThrow(%swift.error* %0)
// CHECK: store %swift.error* %0
// CHECK: ret i64 undef
sil hidden @TestCallToWillThrowCallBack : $@convention(thin) (@owned _ErrorType) -> (Int64, @error _ErrorType) {
bb0(%0 : $_ErrorType):
builtin "willThrow"(%0 : $_ErrorType) : $()
throw %0 : $_ErrorType // id: %3
}