|
1 |
| -// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-silgen -parse-as-library %s | %FileCheck %s |
| 1 | +// RUN: rm -rf %t && mkdir -p %t |
| 2 | +// RUN: %build-clang-importer-objc-overlays |
| 3 | +// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -emit-silgen -parse-as-library %s | %FileCheck %s |
2 | 4 |
|
3 | 5 | // REQUIRES: objc_interop
|
4 | 6 |
|
@@ -31,10 +33,12 @@ func test0() throws {
|
31 | 33 | // CHECK: assign [[T1]] to [[ERR_TEMP0]]
|
32 | 34 |
|
33 | 35 | // Pull out the boolean value and compare it to zero.
|
34 |
| - // CHECK: [[FN:%.*]] = function_ref @_TF10ObjectiveC22_convertObjCBoolToBoolFVS_8ObjCBoolSb |
35 |
| - // CHECK: [[BOOL:%.*]] = apply [[FN]]([[RESULT]]) |
36 |
| - // CHECK: [[BIT:%.*]] = struct_extract [[BOOL]] |
37 |
| - // CHECK: cond_br [[BIT]], [[NORMAL_BB:bb[0-9]+]], [[ERROR_BB:bb[0-9]+]] |
| 36 | + // CHECK: [[BOOL_OR_INT:%.*]] = struct_extract [[RESULT]] |
| 37 | + // CHECK: [[RAW_VALUE:%.*]] = struct_extract [[BOOL_OR_INT]] |
| 38 | + // On some platforms RAW_VALUE will be compared against 0; on others it's |
| 39 | + // already an i1 (bool) and those instructions will be skipped. Just do a |
| 40 | + // looser check. |
| 41 | + // CHECK: cond_br {{%.+}}, [[NORMAL_BB:bb[0-9]+]], [[ERROR_BB:bb[0-9]+]] |
38 | 42 | try ErrorProne.fail()
|
39 | 43 |
|
40 | 44 | // Normal path: fall out and return.
|
@@ -229,3 +233,39 @@ func testPreservedResult() throws -> CInt {
|
229 | 233 | // CHECK-NOT: release
|
230 | 234 | // CHECK: return [[RESULT]]
|
231 | 235 | // CHECK: [[ERROR_BB]]
|
| 236 | + |
| 237 | +func testPreservedResultBridged() throws -> Int { |
| 238 | + return try ErrorProne.ounceWord() |
| 239 | +} |
| 240 | + |
| 241 | +// CHECK-LABEL: sil hidden @_TF14foreign_errors26testPreservedResultBridgedFzT_Si |
| 242 | +// CHECK: [[T0:%.*]] = metatype $@thick ErrorProne.Type |
| 243 | +// CHECK: [[T1:%.*]] = class_method [volatile] [[T0]] : $@thick ErrorProne.Type, #ErrorProne.ounceWord!1.foreign : (ErrorProne.Type) -> () throws -> Int , $@convention(objc_method) (ImplicitlyUnwrappedOptional<AutoreleasingUnsafeMutablePointer<Optional<NSError>>>, @objc_metatype ErrorProne.Type) -> Int |
| 244 | +// CHECK: [[OPTERR:%.*]] = alloc_stack $Optional<NSError> |
| 245 | +// CHECK: [[RESULT:%.*]] = apply [[T1]]( |
| 246 | +// CHECK: [[T0:%.*]] = struct_extract [[RESULT]] |
| 247 | +// CHECK: [[T1:%.*]] = integer_literal $[[PRIM:Builtin.Int[0-9]+]], 0 |
| 248 | +// CHECK: [[T2:%.*]] = builtin "cmp_ne_Int{{.*}}"([[T0]] : $[[PRIM]], [[T1]] : $[[PRIM]]) |
| 249 | +// CHECK: cond_br [[T2]], [[NORMAL_BB:bb[0-9]+]], [[ERROR_BB:bb[0-9]+]] |
| 250 | +// CHECK: [[NORMAL_BB]]: |
| 251 | +// CHECK-NOT: release |
| 252 | +// CHECK: return [[RESULT]] |
| 253 | +// CHECK: [[ERROR_BB]] |
| 254 | + |
| 255 | +func testPreservedResultInverted() throws { |
| 256 | + try ErrorProne.once() |
| 257 | +} |
| 258 | + |
| 259 | +// CHECK-LABEL: sil hidden @_TF14foreign_errors27testPreservedResultInvertedFzT_T_ |
| 260 | +// CHECK: [[T0:%.*]] = metatype $@thick ErrorProne.Type |
| 261 | +// CHECK: [[T1:%.*]] = class_method [volatile] [[T0]] : $@thick ErrorProne.Type, #ErrorProne.once!1.foreign : (ErrorProne.Type) -> () throws -> () , $@convention(objc_method) (ImplicitlyUnwrappedOptional<AutoreleasingUnsafeMutablePointer<Optional<NSError>>>, @objc_metatype ErrorProne.Type) -> Int32 |
| 262 | +// CHECK: [[OPTERR:%.*]] = alloc_stack $Optional<NSError> |
| 263 | +// CHECK: [[RESULT:%.*]] = apply [[T1]]( |
| 264 | +// CHECK: [[T0:%.*]] = struct_extract [[RESULT]] |
| 265 | +// CHECK: [[T1:%.*]] = integer_literal $[[PRIM:Builtin.Int[0-9]+]], 0 |
| 266 | +// CHECK: [[T2:%.*]] = builtin "cmp_ne_Int32"([[T0]] : $[[PRIM]], [[T1]] : $[[PRIM]]) |
| 267 | +// CHECK: cond_br [[T2]], [[ERROR_BB:bb[0-9]+]], [[NORMAL_BB:bb[0-9]+]] |
| 268 | +// CHECK: [[NORMAL_BB]]: |
| 269 | +// CHECK-NOT: release |
| 270 | +// CHECK: return {{%.+}} : $() |
| 271 | +// CHECK: [[ERROR_BB]] |
0 commit comments