Skip to content

Commit 07b76cd

Browse files
committed
Add more tests
1 parent ca2078a commit 07b76cd

15 files changed

+109
-72
lines changed

lib/IRGen/GenClangDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ clang::Decl *getDeclWithExecutableCode(clang::Decl *decl) {
6565
return rd->getDefinition();
6666
}
6767
}
68-
6968
return nullptr;
7069
}
7170

@@ -98,6 +97,9 @@ void IRGenModule::emitClangDecl(const clang::Decl *decl) {
9897
if (DC->isFileContext())
9998
break;
10099
D = cast<const clang::Decl>(DC);
100+
if (DC->isRecord()) {
101+
break;
102+
}
101103
}
102104
if (!GlobalClangDecls.insert(D->getCanonicalDecl()).second)
103105
return;

test/Interop/Cxx/members/Inputs/call-constructor copy.h

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

test/Interop/Cxx/members/Inputs/call-constructor.h

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

test/Interop/Cxx/members/Inputs/call-method.h

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef TEST_INTEROP_CXX_MEMBERS_INPUTS_CONSTRUCTOR_CALLS_FUNCTION_H
2+
#define TEST_INTEROP_CXX_MEMBERS_INPUTS_CONSTRUCTOR_CALLS_FUNCTION_H
3+
4+
inline int increment(int t) { return t + 1; }
5+
6+
struct Incrementor {
7+
int incrementee;
8+
Incrementor(int value) : incrementee(increment(value)) {}
9+
};
10+
11+
inline int callConstructor(int value) { return Incrementor(value).incrementee; }
12+
13+
#endif // TEST_INTEROP_CXX_MEMBERS_INPUTS_CONSTRUCTOR_CALLS_FUNCTION_H
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef TEST_INTEROP_CXX_MEMBERS_INPUTS_CONSTRUCTOR_CALLS_METHOD_H
2+
#define TEST_INTEROP_CXX_MEMBERS_INPUTS_CONSTRUCTOR_CALLS_METHOD_H
3+
4+
struct Increment {
5+
int increment(int t) { return t + 1; }
6+
};
7+
8+
struct IncrementUser {
9+
int incrementee;
10+
IncrementUser(int value) { incrementee = Increment().increment(value); }
11+
};
12+
13+
inline int callConstructor(int value) { return IncrementUser(value).incrementee; }
14+
15+
#endif // TEST_INTEROP_CXX_MEMBERS_INPUTS_CONSTRUCTOR_CALLS_METHOD_H
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef TEST_INTEROP_CXX_MEMBERS_INPUTS_METHOD_CALLS_FUNCTION_H
2+
#define TEST_INTEROP_CXX_MEMBERS_INPUTS_METHOD_CALLS_FUNCTION_H
3+
4+
inline int increment(int t) { return t + 1; }
5+
6+
struct Incrementor {
7+
int callIncrement(int value) { return increment(value); }
8+
};
9+
10+
inline int callMethod(int value) { return Incrementor().callIncrement(value); }
11+
12+
#endif // TEST_INTEROP_CXX_MEMBERS_INPUTS_METHOD_CALLS_FUNCTION_H
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef TEST_INTEROP_CXX_MEMBERS_INPUTS_METHOD_CALLS_METHOD_H
2+
#define TEST_INTEROP_CXX_MEMBERS_INPUTS_METHOD_CALLS_METHOD_H
3+
4+
struct Incrementor {
5+
int increment(int t) { return t + 1; }
6+
};
7+
8+
struct IncrementUser {
9+
int callIncrement(int value) { return Incrementor().increment(value); }
10+
};
11+
12+
inline int callMethod(int value) {
13+
return IncrementUser().callIncrement(value);
14+
}
15+
16+
#endif // TEST_INTEROP_CXX_MEMBERS_INPUTS_METHOD_CALLS_METHOD_H
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
module CallConstructor {
2-
header "call-constructor.h"
1+
module ConstructorCallsFunction {
2+
header "constructor-calls-function.h"
33
}
44

5-
module CallMethod {
6-
header "call-method.h"
5+
module ConstructorCalls {
6+
header "constructor-calls-method.h"
7+
}
8+
9+
module MethodCallsFunction {
10+
header "method-calls-function.h"
11+
}
12+
13+
module MethodCallsMethod {
14+
header "method-calls-method.h"
715
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
22

3-
import CallConstructor
3+
import ConstructorCallsFunction
44

55
public func getIncrementorValue() -> CInt {
6-
return useIncrementor()
6+
return callConstructor(41)
77
}
88

99
// CHECK: define linkonce_odr i32 @_Z9incrementi(i32 %t)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop)
2+
//
3+
// REQUIRES: executable_test
4+
5+
import ConstructorCallsFunction
6+
import StdlibUnittest
7+
8+
var MembersTestSuite = TestSuite("MembersTestSuite")
9+
10+
MembersTestSuite.test("emit-function-from-called-constructor") {
11+
expectEqual(42, callConstructor(41))
12+
}
13+
14+
runAllTests()
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s
22

3-
import CallMethod
3+
import MethodCallsFunction
44

55
public func getValueFromMethod() -> CInt {
6-
return callMethod()
6+
return callMethod(41)
77
}
88

99
// CHECK: define linkonce_odr i32 @_Z9incrementi(i32 %t)

test/Interop/Cxx/members/emit-from-called-constructor.swift renamed to test/Interop/Cxx/members/emit-function-from-called-method.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
//
33
// REQUIRES: executable_test
44

5-
import CallConstructor
5+
import MethodCallsFunction
66
import StdlibUnittest
77

88
var MembersTestSuite = TestSuite("MembersTestSuite")
99

10-
MembersTestSuite.test("emit-from-called-constructor") {
11-
expectEqual(42, useIncrementor())
10+
MembersTestSuite.test("emit-function-from-called-method") {
11+
expectEqual(42, callMethod(41))
1212
}
1313

1414
runAllTests()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop)
2+
//
3+
// REQUIRES: executable_test
4+
5+
import ConstructorCallsMethod
6+
import StdlibUnittest
7+
8+
var MembersTestSuite = TestSuite("MembersTestSuite")
9+
10+
MembersTestSuite.test("emit-method-from-called-constructor") {
11+
expectEqual(42, callConstructor(41))
12+
}
13+
14+
runAllTests()

test/Interop/Cxx/members/emit-from-called-method.swift renamed to test/Interop/Cxx/members/emit-method-from-called-method.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
//
33
// REQUIRES: executable_test
44

5-
import CallMethod
5+
import MethodCallsMethod
66
import StdlibUnittest
77

88
var MembersTestSuite = TestSuite("MembersTestSuite")
99

10-
MembersTestSuite.test("emit-from-called-method") {
11-
expectEqual(42, callMethod())
10+
MembersTestSuite.test("emit-method-from-called-method") {
11+
expectEqual(42, callMethod(41))
1212
}
1313

1414
runAllTests()

0 commit comments

Comments
 (0)