-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Generate IR for decls called from members #35056
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
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2e44b61
Add test
scentini b37c9e5
More tests
scentini 0f327e9
WIP
scentini 0af1d9b
Traverse CXXRecordDecls
scentini 06af9fa
Tweaks
hlopko 9252498
Productionalizing
hlopko ca2078a
Productionalize
scentini 07b76cd
Add more tests
scentini 9153dd9
Add more tests
scentini 6559d45
Polish PR
scentini aa8cbb4
Merge branch 'main' into function-in-constructor
scentini 35f2b25
Fix irgen tests for Windows
scentini 33a109f
Remove wrongly added file
scentini 5a753b2
Handle ConstructExpr correctly
scentini ba25b61
Remove unnecessary check
scentini 54e220f
Update comments
scentini 6c73952
Correctly handle Field decls
scentini 01fa6dc
merge branch 'main' into function-in-constructor
scentini edb3312
Rename tests
scentini 8bcef1b
Point to SR entry
scentini 87e89ed
Move tests into a hopefully better named directory
scentini 3ff1362
Remove wrongly named tests
scentini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
.../Cxx/class/inline-function-codegen/Inputs/constructor-calls-function-from-nested-struct.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_CONSTRUCTOR_CALLS_FUNCTION_FROM_NESTED_STRUCT_H | ||
#define TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_CONSTRUCTOR_CALLS_FUNCTION_FROM_NESTED_STRUCT_H | ||
|
||
inline int increment(int t) { return t + 1; } | ||
|
||
struct IncrementUser { | ||
struct Incrementor { | ||
int value; | ||
Incrementor(int v) { value = increment(v); } | ||
}; | ||
}; | ||
|
||
inline int callConstructor(int value) { | ||
return IncrementUser::Incrementor(value).value; | ||
} | ||
|
||
#endif // TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_CONSTRUCTOR_CALLS_FUNCTION_FROM_NESTED_STRUCT_H |
13 changes: 13 additions & 0 deletions
13
test/Interop/Cxx/class/inline-function-codegen/Inputs/constructor-calls-function.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_CONSTRUCTOR_CALLS_FUNCTION_H | ||
#define TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_CONSTRUCTOR_CALLS_FUNCTION_H | ||
|
||
inline int increment(int t) { return t + 1; } | ||
|
||
struct Incrementor { | ||
int incrementee; | ||
Incrementor(int value) : incrementee(increment(value)) {} | ||
}; | ||
|
||
inline int callConstructor(int value) { return Incrementor(value).incrementee; } | ||
|
||
#endif // TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_CONSTRUCTOR_CALLS_FUNCTION_H |
17 changes: 17 additions & 0 deletions
17
test/Interop/Cxx/class/inline-function-codegen/Inputs/constructor-calls-method.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_CONSTRUCTOR_CALLS_METHOD_H | ||
#define TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_CONSTRUCTOR_CALLS_METHOD_H | ||
|
||
struct Incrementor { | ||
int increment(int t) { return t + 1; } | ||
}; | ||
|
||
struct IncrementUser { | ||
int incrementee; | ||
IncrementUser(int value) { incrementee = Incrementor().increment(value); } | ||
}; | ||
|
||
inline int callConstructor(int value) { | ||
return IncrementUser(value).incrementee; | ||
} | ||
|
||
#endif // TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_CONSTRUCTOR_CALLS_METHOD_H |
12 changes: 12 additions & 0 deletions
12
test/Interop/Cxx/class/inline-function-codegen/Inputs/field-init-calls-function.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_FIELD_INIT_CALLS_FUNCTION_H | ||
#define TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_FIELD_INIT_CALLS_FUNCTION_H | ||
|
||
inline int increment(int t) { return t + 1; } | ||
|
||
struct Incrementor { | ||
int incrementee = increment(41); | ||
}; | ||
|
||
inline int initializeField() { return Incrementor().incrementee; } | ||
|
||
#endif // TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_FIELD_INIT_CALLS_FUNCTION_H |
12 changes: 12 additions & 0 deletions
12
test/Interop/Cxx/class/inline-function-codegen/Inputs/method-calls-function.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_METHOD_CALLS_FUNCTION_H | ||
#define TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_METHOD_CALLS_FUNCTION_H | ||
|
||
inline int increment(int t) { return t + 1; } | ||
|
||
struct Incrementor { | ||
int callIncrement(int value) { return increment(value); } | ||
}; | ||
|
||
inline int callMethod(int value) { return Incrementor().callIncrement(value); } | ||
|
||
#endif // TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_METHOD_CALLS_FUNCTION_H |
15 changes: 15 additions & 0 deletions
15
...Interop/Cxx/class/inline-function-codegen/Inputs/method-calls-method-from-nested-struct.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_METHOD_CALLS_METHOD_FROM_NESTED_STRUCT_H | ||
#define TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_METHOD_CALLS_METHOD_FROM_NESTED_STRUCT_H | ||
|
||
struct IncrementUser { | ||
struct Incrementor { | ||
int increment(int t) { return t + 1; } | ||
}; | ||
int callIncrement(int value) { return Incrementor().increment(value); } | ||
}; | ||
|
||
inline int callMethod(int value) { | ||
return IncrementUser().callIncrement(value); | ||
} | ||
|
||
#endif // TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_METHOD_CALLS_METHOD_FROM_NESTED_STRUCT_H |
16 changes: 16 additions & 0 deletions
16
test/Interop/Cxx/class/inline-function-codegen/Inputs/method-calls-method.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_METHOD_CALLS_METHOD_H | ||
#define TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_METHOD_CALLS_METHOD_H | ||
|
||
struct Incrementor { | ||
int increment(int t) { return t + 1; } | ||
}; | ||
|
||
struct IncrementUser { | ||
int callIncrement(int value) { return Incrementor().increment(value); } | ||
}; | ||
|
||
inline int callMethod(int value) { | ||
return IncrementUser().callIncrement(value); | ||
} | ||
|
||
#endif // TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_METHOD_CALLS_METHOD_H |
31 changes: 31 additions & 0 deletions
31
test/Interop/Cxx/class/inline-function-codegen/Inputs/module.modulemap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module ConstructorCallsFunction { | ||
header "constructor-calls-function.h" | ||
} | ||
|
||
module ConstructorCallsFunctionFromNestedStruct { | ||
header "constructor-calls-function-from-nested-struct.h" | ||
} | ||
|
||
module ConstructorCallsMethod { | ||
header "constructor-calls-method.h" | ||
} | ||
|
||
module FieldInitCallsFunction { | ||
header "field-init-calls-function.h" | ||
} | ||
|
||
module MethodCallsFunction { | ||
header "method-calls-function.h" | ||
} | ||
|
||
module MethodCallsMethod { | ||
header "method-calls-method.h" | ||
} | ||
|
||
module MethodCallsMethodFromNestedStruct { | ||
header "method-calls-method-from-nested-struct.h" | ||
} | ||
|
||
module StaticVarInitCallsFunction { | ||
header "static-var-init-calls-function.h" | ||
} |
16 changes: 16 additions & 0 deletions
16
test/Interop/Cxx/class/inline-function-codegen/Inputs/static-var-init-calls-function.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_STATIC_VAR_INIT_CALLS_FUNCTION_H | ||
#define TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_STATIC_VAR_INIT_CALLS_FUNCTION_H | ||
|
||
inline int increment(int t) { return t + 1; } | ||
|
||
struct Incrementor { | ||
static int incrementee; | ||
}; | ||
|
||
int Incrementor::incrementee = increment(41); | ||
|
||
inline int initializeStaticVar() { | ||
return Incrementor::incrementee; | ||
} | ||
|
||
#endif // TEST_INTEROP_CXX_CLASS_INLINE_FUNCTION_THROUGH_MEMBER_INPUTS_STATIC_VAR_INIT_CALLS_FUNCTION_H |
14 changes: 14 additions & 0 deletions
14
test/Interop/Cxx/class/inline-function-codegen/constructor-calls-function-execution.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop) | ||
// | ||
// REQUIRES: executable_test | ||
|
||
import ConstructorCallsFunction | ||
import StdlibUnittest | ||
|
||
var MembersTestSuite = TestSuite("MembersTestSuite") | ||
|
||
MembersTestSuite.test("constructor calls function") { | ||
expectEqual(42, callConstructor(41)) | ||
} | ||
|
||
runAllTests() |
14 changes: 14 additions & 0 deletions
14
...ass/inline-function-codegen/constructor-calls-function-from-nested-struct-execution.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop) | ||
// | ||
// REQUIRES: executable_test | ||
|
||
import ConstructorCallsFunctionFromNestedStruct | ||
import StdlibUnittest | ||
|
||
var MembersTestSuite = TestSuite("MembersTestSuite") | ||
|
||
MembersTestSuite.test("constructor calls function from nested struct") { | ||
expectEqual(42, callConstructor(41)) | ||
} | ||
|
||
runAllTests() |
9 changes: 9 additions & 0 deletions
9
...x/class/inline-function-codegen/constructor-calls-function-from-nested-struct-irgen.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s | ||
|
||
import ConstructorCallsFunctionFromNestedStruct | ||
|
||
public func getIncrementorValue() -> CInt { | ||
return callConstructor(41) | ||
} | ||
|
||
// CHECK: define linkonce_odr{{( dso_local)?}} i32 @{{_Z9incrementi|"\?increment@@YAHH@Z"}}(i32 %t) |
9 changes: 9 additions & 0 deletions
9
test/Interop/Cxx/class/inline-function-codegen/constructor-calls-function-irgen.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s | ||
|
||
import ConstructorCallsFunction | ||
|
||
public func getIncrementorValue() -> CInt { | ||
return callConstructor(41) | ||
} | ||
|
||
// CHECK: define linkonce_odr{{( dso_local)?}} i32 @{{_Z9incrementi|"\?increment@@YAHH@Z"}}(i32 %t) |
14 changes: 14 additions & 0 deletions
14
test/Interop/Cxx/class/inline-function-codegen/constructor-calls-method-execution.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop) | ||
// | ||
// REQUIRES: executable_test | ||
|
||
import ConstructorCallsMethod | ||
import StdlibUnittest | ||
|
||
var MembersTestSuite = TestSuite("MembersTestSuite") | ||
|
||
MembersTestSuite.test("constructor calls method") { | ||
expectEqual(42, callConstructor(41)) | ||
} | ||
|
||
runAllTests() |
9 changes: 9 additions & 0 deletions
9
test/Interop/Cxx/class/inline-function-codegen/constructor-calls-method-irgen.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s | ||
|
||
import ConstructorCallsMethod | ||
|
||
public func getIncrementorValue() -> CInt { | ||
return callConstructor(41) | ||
} | ||
|
||
// CHECK: define linkonce_odr{{( dso_local)?}} i32 @{{_ZN11Incrementor9incrementEi|"\?increment@Incrementor@@QEAAHH@Z"}}(%struct.Incrementor* %this, i32 %t) |
14 changes: 14 additions & 0 deletions
14
test/Interop/Cxx/class/inline-function-codegen/field-init-calls-function-execution.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop) | ||
// | ||
// REQUIRES: executable_test | ||
|
||
import FieldInitCallsFunction | ||
import StdlibUnittest | ||
|
||
var MembersTestSuite = TestSuite("MembersTestSuite") | ||
|
||
MembersTestSuite.test("field init calls function") { | ||
expectEqual(42, initializeField()) | ||
} | ||
|
||
runAllTests() |
9 changes: 9 additions & 0 deletions
9
test/Interop/Cxx/class/inline-function-codegen/field-init-calls-function-irgen.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s | ||
|
||
import FieldInitCallsFunction | ||
|
||
public func getInitializedField() -> CInt { | ||
return initializeField() | ||
} | ||
|
||
// CHECK: define linkonce_odr{{( dso_local)?}} i32 @{{_Z9incrementi|"\?increment@@YAHH@Z"}}(i32 %t) |
14 changes: 14 additions & 0 deletions
14
test/Interop/Cxx/class/inline-function-codegen/method-calls-function-execution.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-cxx-interop) | ||
// | ||
// REQUIRES: executable_test | ||
|
||
import MethodCallsFunction | ||
import StdlibUnittest | ||
|
||
var MembersTestSuite = TestSuite("MembersTestSuite") | ||
|
||
MembersTestSuite.test("method calls function") { | ||
expectEqual(42, callMethod(41)) | ||
} | ||
|
||
runAllTests() |
9 changes: 9 additions & 0 deletions
9
test/Interop/Cxx/class/inline-function-codegen/method-calls-function-irgen.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// RUN: %target-swift-emit-ir %s -I %S/Inputs -enable-cxx-interop | %FileCheck %s | ||
|
||
import MethodCallsFunction | ||
|
||
public func getValueFromMethod() -> CInt { | ||
return callMethod(41) | ||
} | ||
|
||
// CHECK: define linkonce_odr{{( dso_local)?}} i32 @{{_Z9incrementi|"\?increment@@YAHH@Z"}}(i32 %t) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.