Skip to content

Commit 9e84c84

Browse files
committed
[cxx-interop] Fix tests that passed -module-name Swift
`Swift` is the name of the Swift standard library module. Creating another module with this name breaks assumptions in the compiler and caused these two tests to fail.
1 parent 2b4a7ff commit 9e84c84

File tree

4 files changed

+154
-119
lines changed

4 files changed

+154
-119
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Target-specific tests for C++ constructor call code generation.
2+
3+
// RUN: %swift -module-name MySwift -target armv7-unknown-linux-androideabi -dump-clang-diagnostics -I %S/Inputs -enable-experimental-cxx-interop -emit-ir %s -parse-stdlib -parse-as-library -disable-legacy-type-info | %FileCheck %s -check-prefix=ITANIUM_ARM
4+
5+
// REQUIRES: OS=linux-android || OS=linux-androideabi
6+
7+
import Constructors
8+
import TypeClassification
9+
10+
public func createHasVirtualBase() -> HasVirtualBase {
11+
// ITANIUM_ARM: define protected swiftcc void @"$ss20createHasVirtualBaseSo0bcD0VyF"(%TSo14HasVirtualBaseV* noalias nocapture sret({{.*}}) %0)
12+
// To verify that the thunk is inlined, make sure there's no intervening
13+
// `define`, i.e. the call to the C++ constructor happens in
14+
// createHasVirtualBase(), not some later function.
15+
// ITANIUM_ARM-NOT: define
16+
// Note `this` return type.
17+
// ITANIUM_ARM: call %struct.HasVirtualBase* @_ZN14HasVirtualBaseC1E7ArgType(%struct.HasVirtualBase* %{{[0-9]+}}, [1 x i32] %{{[0-9]+}})
18+
return HasVirtualBase(ArgType())
19+
}
20+
21+
public func createImplicitDefaultConstructor() -> ImplicitDefaultConstructor {
22+
// ITANIUM_ARM: define protected swiftcc i32 @"$ss32createImplicitDefaultConstructorSo0bcD0VyF"()
23+
// ITANIUM_ARM-NOT: define
24+
// Note `this` return type.
25+
// ITANIUM_ARM: call %struct.ImplicitDefaultConstructor* @_ZN26ImplicitDefaultConstructorC2Ev(%struct.ImplicitDefaultConstructor* %{{[0-9]+}})
26+
return ImplicitDefaultConstructor()
27+
}
28+
29+
public func createStructWithSubobjectCopyConstructorAndValue() {
30+
// ITANIUM_ARM-LABEL: define protected swiftcc void @"$ss48createStructWithSubobjectCopyConstructorAndValueyyF"()
31+
// ITANIUM_ARM: [[MEMBER:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV
32+
// ITANIUM_ARM: [[OBJ:%.*]] = alloca %TSo42StructWithSubobjectCopyConstructorAndValueV
33+
// ITANIUM_ARM: [[TMP:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV
34+
// ITANIUM_ARM: [[MEMBER_AS_STRUCT:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]] to %struct.StructWithCopyConstructorAndValue*
35+
// ITANIUM_ARM: call %struct.StructWithCopyConstructorAndValue* @_ZN33StructWithCopyConstructorAndValueC2Ev(%struct.StructWithCopyConstructorAndValue* [[MEMBER_AS_STRUCT]])
36+
// ITANIUM_ARM: [[TMP_STRUCT:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[TMP]] to %struct.StructWithCopyConstructorAndValue*
37+
// ITANIUM_ARM: [[MEMBER_AS_STRUCT_2:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]] to %struct.StructWithCopyConstructorAndValue*
38+
// ITANIUM_ARM: call %struct.StructWithCopyConstructorAndValue* @_ZN33StructWithCopyConstructorAndValueC2ERKS_(%struct.StructWithCopyConstructorAndValue* [[TMP_STRUCT]], %struct.StructWithCopyConstructorAndValue* [[MEMBER_AS_STRUCT_2]])
39+
// ITANIUM_ARM: ret void
40+
let member = StructWithCopyConstructorAndValue()
41+
let obj = StructWithSubobjectCopyConstructorAndValue(member: member)
42+
}
43+
44+
public func createTemplatedConstructor() {
45+
// ITANIUM_ARM-LABEL: define protected swiftcc void @"$ss26createTemplatedConstructoryyF"()
46+
// ITANIUM_ARM: [[OBJ:%.*]] = alloca %TSo20TemplatedConstructorV
47+
// ITANIUM_ARM: [[IVAL:%.*]] = load [1 x i32], [1 x i32]*
48+
// ITANIUM_ARM: [[OBJ_AS_STRUCT:%.*]] = bitcast %TSo20TemplatedConstructorV* [[OBJ]] to %struct.TemplatedConstructor*
49+
// ITANIUM_ARM: call %struct.TemplatedConstructor* @_ZN20TemplatedConstructorC2I7ArgTypeEET_(%struct.TemplatedConstructor* [[OBJ_AS_STRUCT]], [1 x i32] [[IVAL]])
50+
// ITANIUM_ARM: ret void
51+
52+
// ITANIUM_ARM-LABEL: define {{.*}}%struct.TemplatedConstructor* @_ZN20TemplatedConstructorC2I7ArgTypeEET_(%struct.TemplatedConstructor* {{.*}}, [1 x i32] {{.*}})
53+
let templated = TemplatedConstructor(ArgType())
54+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Target-specific tests for C++ constructor call code generation.
2+
3+
// RUN: %swift -module-name MySwift -target x86_64-apple-macosx10.9 -dump-clang-diagnostics -I %S/Inputs -enable-experimental-cxx-interop -emit-ir %s -parse-stdlib -parse-as-library -disable-legacy-type-info | %FileCheck %s -check-prefix=ITANIUM_X64
4+
5+
// REQUIRES: OS=macosx
6+
7+
import Constructors
8+
import TypeClassification
9+
10+
public func createHasVirtualBase() -> HasVirtualBase {
11+
// ITANIUM_X64: define swiftcc void @"$s7MySwift20createHasVirtualBaseSo0deF0VyF"(%TSo14HasVirtualBaseV* noalias nocapture sret({{.*}}) %0)
12+
// ITANIUM_X64-NOT: define
13+
// ITANIUM_X64: call void @_ZN14HasVirtualBaseC1E7ArgType(%struct.HasVirtualBase* %{{[0-9]+}}, i32 %{{[0-9]+}})
14+
return HasVirtualBase(ArgType())
15+
}
16+
17+
public func createImplicitDefaultConstructor() -> ImplicitDefaultConstructor {
18+
// ITANIUM_X64: define swiftcc i32 @"$s7MySwift32createImplicitDefaultConstructorSo0deF0VyF"()
19+
// ITANIUM_X64-NOT: define
20+
// ITANIUM_X64: call void @_ZN26ImplicitDefaultConstructorC1Ev(%struct.ImplicitDefaultConstructor* %{{[0-9]+}})
21+
return ImplicitDefaultConstructor()
22+
}
23+
24+
public func createStructWithSubobjectCopyConstructorAndValue() {
25+
// ITANIUM_X64-LABEL: define swiftcc void @"$s7MySwift48createStructWithSubobjectCopyConstructorAndValueyyF"()
26+
// ITANIUM_X64: [[MEMBER:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV
27+
// ITANIUM_X64: [[OBJ:%.*]] = alloca %TSo42StructWithSubobjectCopyConstructorAndValueV
28+
// ITANIUM_X64: [[TMP:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV
29+
// ITANIUM_X64: [[MEMBER_AS_STRUCT:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]] to %struct.StructWithCopyConstructorAndValue*
30+
// ITANIUM_X64: void @_ZN33StructWithCopyConstructorAndValueC1Ev(%struct.StructWithCopyConstructorAndValue* [[MEMBER_AS_STRUCT]])
31+
// ITANIUM_X64: [[TMP_STRUCT:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[TMP]] to %struct.StructWithCopyConstructorAndValue*
32+
// ITANIUM_X64: [[MEMBER_AS_STRUCT_2:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]] to %struct.StructWithCopyConstructorAndValue*
33+
// ITANIUM_X64: call void @_ZN33StructWithCopyConstructorAndValueC1ERKS_(%struct.StructWithCopyConstructorAndValue* [[TMP_STRUCT]], %struct.StructWithCopyConstructorAndValue* [[MEMBER_AS_STRUCT_2]])
34+
// ITANIUM_X64: ret void
35+
let member = StructWithCopyConstructorAndValue()
36+
let obj = StructWithSubobjectCopyConstructorAndValue(member: member)
37+
}
38+
39+
public func createTemplatedConstructor() {
40+
// ITANIUM_X64-LABEL: define swiftcc void @"$s7MySwift26createTemplatedConstructoryyF"()
41+
// ITANIUM_X64: [[OBJ:%.*]] = alloca %TSo20TemplatedConstructorV
42+
// ITANIUM_X64: [[IVAL:%.*]] = load i32, i32*
43+
// ITANIUM_X64: [[OBJ_AS_STRUCT:%.*]] = bitcast %TSo20TemplatedConstructorV* [[OBJ]] to %struct.TemplatedConstructor*
44+
// ITANIUM_X64: call void @_ZN20TemplatedConstructorC1I7ArgTypeEET_(%struct.TemplatedConstructor* [[OBJ_AS_STRUCT]], i32 [[IVAL]])
45+
// ITANIUM_X64: ret void
46+
47+
// ITANIUM_X64-LABEL: define {{.*}}void @_ZN20TemplatedConstructorC1I7ArgTypeEET_(%struct.TemplatedConstructor* {{.*}}, i32 {{.*}})
48+
let templated = TemplatedConstructor(ArgType())
49+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Target-specific tests for C++ constructor call code generation.
2+
3+
// RUN: %swift -module-name MySwift -target x86_64-unknown-windows-msvc -dump-clang-diagnostics -I %S/Inputs -enable-experimental-cxx-interop -emit-ir %s -parse-stdlib -parse-as-library -disable-legacy-type-info | %FileCheck %s -check-prefix=MICROSOFT_X64
4+
5+
// REQUIRES: OS=windows-msvc
6+
7+
import Constructors
8+
import TypeClassification
9+
10+
public func createHasVirtualBase() -> HasVirtualBase {
11+
// MICROSOFT_X64: define dllexport swiftcc void @"$ss20createHasVirtualBaseSo0bcD0VyF"(%TSo14HasVirtualBaseV* noalias nocapture sret({{.*}}) %0)
12+
// MICROSOFT_X64-NOT: define
13+
// Note `this` return type and implicit "most derived" argument.
14+
// MICROSOFT_X64: call %struct.HasVirtualBase* @"??0HasVirtualBase@@QEAA@UArgType@@@Z"(%struct.HasVirtualBase* %{{[0-9]+}}, i32 %{{[0-9]+}}, i32 1)
15+
return HasVirtualBase(ArgType())
16+
}
17+
18+
public func createImplicitDefaultConstructor() -> ImplicitDefaultConstructor {
19+
// MICROSOFT_X64: define dllexport swiftcc i32 @"$ss32createImplicitDefaultConstructorSo0bcD0VyF"()
20+
// MICROSOFT_X64-NOT: define
21+
// Note `this` return type but no implicit "most derived" argument.
22+
// MICROSOFT_X64: call %struct.ImplicitDefaultConstructor* @"??0ImplicitDefaultConstructor@@QEAA@XZ"(%struct.ImplicitDefaultConstructor* %{{[0-9]+}})
23+
return ImplicitDefaultConstructor()
24+
}
25+
26+
public func createStructWithSubobjectCopyConstructorAndValue() {
27+
// MICROSOFT_X64-LABEL: define dllexport swiftcc void @"$ss48createStructWithSubobjectCopyConstructorAndValueyyF"()
28+
// MICROSOFT_X64: [[MEMBER:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV
29+
// MICROSOFT_X64: [[OBJ:%.*]] = alloca %TSo42StructWithSubobjectCopyConstructorAndValueV
30+
// MICROSOFT_X64: [[TMP:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV
31+
// MICROSOFT_X64: [[MEMBER_AS_STRUCT:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]] to %struct.StructWithCopyConstructorAndValue*
32+
// MICROSOFT_X64: call %struct.StructWithCopyConstructorAndValue* @"??0StructWithCopyConstructorAndValue@@QEAA@XZ"(%struct.StructWithCopyConstructorAndValue* [[MEMBER_AS_STRUCT]])
33+
// MICROSOFT_X64: [[TMP_STRUCT:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[TMP]] to %struct.StructWithCopyConstructorAndValue*
34+
// MICROSOFT_X64: [[MEMBER_AS_STRUCT_2:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]] to %struct.StructWithCopyConstructorAndValue*
35+
// MICROSOFT_X64: call %struct.StructWithCopyConstructorAndValue* @"??0StructWithCopyConstructorAndValue@@QEAA@AEBU0@@Z"(%struct.StructWithCopyConstructorAndValue* [[TMP_STRUCT]], %struct.StructWithCopyConstructorAndValue* [[MEMBER_AS_STRUCT_2]])
36+
// MICROSOFT_X64: ret void
37+
let member = StructWithCopyConstructorAndValue()
38+
let obj = StructWithSubobjectCopyConstructorAndValue(member: member)
39+
}
40+
41+
public func createTemplatedConstructor() {
42+
// MICROSOFT_X64-LABEL: define dllexport swiftcc void @"$ss26createTemplatedConstructoryyF"()
43+
// MICROSOFT_X64: [[OBJ:%.*]] = alloca %TSo20TemplatedConstructorV
44+
// MICROSOFT_X64: [[IVAL:%.*]] = load i32, i32*
45+
// MICROSOFT_X64: [[OBJ_AS_STRUCT:%.*]] = bitcast %TSo20TemplatedConstructorV* [[OBJ]] to %struct.TemplatedConstructor*
46+
// MICROSOFT_X64: call %struct.TemplatedConstructor* @"??$?0UArgType@@@TemplatedConstructor@@QEAA@UArgType@@@Z"(%struct.TemplatedConstructor* [[OBJ_AS_STRUCT]], i32 [[IVAL]])
47+
// MICROSOFT_X64: ret void
48+
49+
// MICROSOFT_X64-LABEL: define {{.*}}%struct.TemplatedConstructor* @"??$?0UArgType@@@TemplatedConstructor@@QEAA@UArgType@@@Z"(%struct.TemplatedConstructor* {{.*}}, i32 {{.*}})
50+
let templated = TemplatedConstructor(ArgType())
51+
}

test/Interop/Cxx/class/constructors-irgen.swift

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)