mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Currently the following code doesn't work when `callConstructor()` is called from Swift:
```cc
inline int increment(int value) {
return value + 1;
}
struct Incrementor {
int incrementee;
Incrementor(int value) : incrementee(increment(value)) {}
}
int callConstructor(int value) {
return Incrementor(value).incrementee;
}
```
The issue is that we don't generate `IR` for the `increment()` function when it's only called from a constructor or a method.
Swift is aware of the existence of `increment()` and we see it in `IR` as `declare incrementEi`, however, as we don't to emit a definition, we get the following error:
```
Incrementor::Incrementor(int): error: undefined reference to 'increment(int)'
```
This PR fixes this by visiting constructors and methods in `IRGen` and calling `HandleTopLevelDecl()` with all used declarations, which results in emitting definitions for the used declarations.
Co-authored-by: Marcel Hlopko <hlopko@google.com>
13 lines
469 B
C
13 lines
469 B
C
#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
|