Commit Graph

4 Commits

Author SHA1 Message Date
zoecarver
839839f924 [cxx-interop] Rename enable-cxx-interop -> enable-experimental-cxx-interop.
Also removes the driver flag, this will now also always be guarded on `-Xfrontend`.
2022-04-07 19:15:25 -07:00
Arnold Schwaighofer
ee6441c4d2 Fix test/Interop/Cxx 2021-08-05 12:15:23 -07:00
Saleem Abdulrasool
3db60d2c20 test: update Interop.cxx tests for newer clang
Clang will properly mark the C++ `this` parameter as `nonnull` and
`dereferenceable(1)` as per the C++ specification.  Update the tests to
accept the newer attributes.
2021-01-21 12:30:53 -08:00
scentini
0b3990c141 [cxx-interop] Generate IR for decls called from members (#35056)
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>
2021-01-21 10:16:25 +01:00