Skip to content

[NFC] [cxx-interop] Add SILGen tests for synthesized initializers. #32658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/Interop/Cxx/class/Inputs/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ module MemberVariables {
module ProtocolConformance {
header "protocol-conformance.h"
}

module SynthesizedInitializers {
header "synthesized-initializers.h"
}
5 changes: 5 additions & 0 deletions test/Interop/Cxx/class/Inputs/synthesized-initializers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
struct EmptyStruct {};

struct IntBox {
int x;
};
46 changes: 46 additions & 0 deletions test/Interop/Cxx/class/synthesized-initializers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// RUN: %target-swift-frontend -I %S/Inputs -enable-cxx-interop -emit-silgen %s | %FileCheck %s

import SynthesizedInitializers

// CHECK-LABEL: sil shared [transparent] [serializable] [ossa] @$sSo11EmptyStructVABycfC : $@convention(method) (@thin EmptyStruct.Type) -> EmptyStruct
// CHECK: bb0(%{{[0-9]+}} : $@thin EmptyStruct.Type):
// CHECK-NEXT: [[BOX:%.*]] = alloc_box ${ var EmptyStruct }
// CHECK-NEXT: [[UNINIT:%.*]] = mark_uninitialized [rootself] [[BOX]] : ${ var EmptyStruct }
// CHECK-NEXT: [[PTR:%.*]] = project_box [[UNINIT]] : ${ var EmptyStruct }, 0
// CHECK-NEXT: [[OBJ:%.*]] = builtin "zeroInitializer"<EmptyStruct>() : $EmptyStruct
// CHECK-NEXT: [[PA:%.*]] = begin_access [modify] [unknown] [[PTR]] : $*EmptyStruct
// CHECK-NEXT: assign [[OBJ]] to [[PA]]
// CHECK-NEXT: end_access [[PA]]
// CHECK-NEXT: [[OUT:%.*]] = load [trivial] [[PTR]]
// CHECK-NEXT: destroy_value [[UNINIT]]
// CHECK-NEXT: return [[OUT]]
// CHECK-LABEL: end sil function '$sSo11EmptyStructVABycfC'
public func emptyTypeNoArgInit() {
let e = EmptyStruct()
}

// CHECK-LABEL: sil shared [transparent] [serializable] [ossa] @$sSo6IntBoxVABycfC : $@convention(method) (@thin IntBox.Type) -> IntBox
// CHECK: bb0(%{{[0-9]+}} : $@thin IntBox.Type):
// CHECK-NEXT: [[BOX:%.*]] = alloc_box ${ var IntBox }
// CHECK-NEXT: [[UNINIT:%.*]] = mark_uninitialized [rootself] [[BOX]] : ${ var IntBox }
// CHECK-NEXT: [[PTR:%.*]] = project_box [[UNINIT]] : ${ var IntBox }, 0
// CHECK-NEXT: [[OBJ:%.*]] = builtin "zeroInitializer"<IntBox>() : $IntBox
// CHECK-NEXT: [[PA:%.*]] = begin_access [modify] [unknown] [[PTR]] : $*IntBox
// CHECK-NEXT: assign [[OBJ]] to [[PA]]
// CHECK-NEXT: end_access [[PA]]
// CHECK-NEXT: [[OUT:%.*]] = load [trivial] [[PTR]]
// CHECK-NEXT: destroy_value [[UNINIT]]
// CHECK-NEXT: return [[OUT]]
// CHECK-LABEL: end sil function '$sSo6IntBoxVABycfC'
public func singleMemberTypeNoArgInit() {
let i = IntBox()
}

// CHECK-LABEL: sil shared [transparent] [serializable] [ossa] @$sSo6IntBoxV1xABs5Int32V_tcfC : $@convention(method) (Int32, @thin IntBox.Type) -> IntBox
// CHECK: bb0([[I:%[0-9]+]] : $Int32, %{{[0-9]+}} : $@thin IntBox.Type):
// CHECK-NEXT: [[S:%.*]] = struct $IntBox ([[I]] : $Int32)
// CHECK-NEXT: return [[S]]
// CHECK-LABEL: end sil function '$sSo6IntBoxV1xABs5Int32V_tcfC'
public func singleMemberTypeValueInit() {
let i = IntBox(x: 42)
}