Skip to content

Commit

Permalink
Add SILGen and IRGen tests for passing Objective-C types to C++
Browse files Browse the repository at this point in the history
constructors.
  • Loading branch information
martinboehme authored and zoecarver committed Oct 9, 2020
1 parent faca489 commit 83b51b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/Interop/Cxx/class/constructors-objc-irgen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/Inputs -enable-cxx-interop -emit-ir %s | %FileCheck %s

// REQUIRES: CPU=x86_64
// REQUIRES: objc_interop

import ConstructorsObjC

public func createConstructorWithNSArrayParam() -> ConstructorWithNSArrayParam {
// CHECK: define swiftcc void @"$s4main33createConstructorWithNSArrayParamSo0cdeF0VyF"()
// CHECK-NOT: define
// CHECK: [[VAR:%[0-9]+]] = alloca %TSo27ConstructorWithNSArrayParamV, align 1
// CHECK: %{{[0-9]+}} = call swiftcc %TSo7NSArrayC* @"$sSa10FoundationE19_bridgeToObjectiveCSo7NSArrayCyF"(%swift.bridge* %{{[0-9]+}}, %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sypN", i32 0, i32 1))
// CHECK: [[CAST_VAR:%[0-9]+]] = bitcast %TSo27ConstructorWithNSArrayParamV* [[VAR]] to %struct.ConstructorWithNSArrayParam*
// CHECK: call void @_ZN27ConstructorWithNSArrayParamC1EP7NSArray(%struct.ConstructorWithNSArrayParam* noalias [[CAST_VAR]], [[VAR]]* %{{[0-9]+}})
return ConstructorWithNSArrayParam([])
}
12 changes: 12 additions & 0 deletions test/Interop/Cxx/class/constructors-objc-silgen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/Inputs -enable-cxx-interop -emit-sil %s | %FileCheck %s

// REQUIRES: objc_interop

import ConstructorsObjC

// CHECK: [[VAR:%[0-9]+]] = alloc_stack $ConstructorWithNSArrayParam
// CHECK: [[TYPE:%[0-9]+]] = metatype $@thin ConstructorWithNSArrayParam.Type
// CHECK: [[OPT_ARRAY:%[0-9]+]] = enum $Optional<NSArray>, #Optional.some!enumelt, %{{[0-9]+}} : $NSArray
// CHECK: [[FUNC:%[0-9]+]] = function_ref @_ZN27ConstructorWithNSArrayParamC1EP7NSArray : $@convention(c) (Optional<NSArray>, @thin ConstructorWithNSArrayParam.Type) -> @out ConstructorWithNSArrayParam
// CHECK: %{{[0-9]+}} = apply [[FUNC]]([[VAR]], [[OPT_ARRAY]], [[TYPE]]) : $@convention(c) (Optional<NSArray>, @thin ConstructorWithNSArrayParam.Type) -> @out ConstructorWithNSArrayParam
let _ = ConstructorWithNSArrayParam([])

0 comments on commit 83b51b9

Please sign in to comment.