Commit Graph

597 Commits

Author SHA1 Message Date
Egor Zhdan
06612934e8 C++ Interop: support mutating attribute for C++ methods
This change teaches ClangImporter to import C++ methods marked with `__attribute__((__swift_attr__("mutating")))` as mutating in Swift. This is useful, for example, when a method mutates `this` despite being `const` in C++ (e.g. via `const_cast`).
2021-11-29 21:13:16 +03:00
Becca Royal-Gordon
ad0e7096ba Make NS_ENUM &c. Sendable even when audited
An explicit swift_attr("@_nonSendable") will override it (except for ns_error_domain where the type is embedded in another type that's forced to be Sendable), but swift_attr("@_nonSendable(_assumed)") will not.
2021-11-19 11:34:02 -08:00
Saleem Abdulrasool
4d44953691 Revert "Support __available__((swift_attr("@Sendable")))" 2021-11-19 07:40:24 -08:00
Becca Royal-Gordon
8751658f6c Make NS_ENUM &c. Sendable even when audited
An explicit swift_attr("@_nonSendable") will override it (except for ns_error_domain where the type is embedded in another type that's forced to be Sendable), but swift_attr("@_nonSendable(_assumed)") will not.
2021-11-12 23:13:29 -08:00
zoecarver
b8e52a7ad2 [cxx-interop] Lazily import members of Clang namespaces and records via requests.
Also adds a ClangImporter request zone and move some requests into it.
2021-10-20 14:52:43 -07:00
Zoe Carver
40422f021b Merge pull request #39664 from zoecarver/lazy-pt9-use-lookup-table
[cxx-interop] Add members to the LookupTable where possible.
2021-10-13 15:29:31 -07:00
zoecarver
eeeb27d66e [cxx-interop] Add members to the LookupTable where possible.
If possible, add imported members to the StructDecl's LookupTable rather than adding them directly as members. This will fix the issues with ordering that #39436 poorly attempted to solve during IRGen.

This also allows us to break out most of the test changes from #39436.
2021-10-13 11:53:58 -07:00
swift-ci
ebad328a4f Merge remote-tracking branch 'origin/main' into rebranch 2021-09-01 09:14:57 -07:00
Min-Yih Hsu
e1023bc323 [DebugInfo] PATCH 2/3: Duplicate logics regarding debug_value_addr
This patch replace all in-memory objects of DebugValueAddrInst with
DebugValueInst + op_deref, and duplicates logics that handles
DebugValueAddrInst with the latter. All related check in the tests
have been updated as well.

Note that this patch neither remove the DebugValueAddrInst class nor
remove `debug_value_addr` syntax in the test inputs.
2021-08-31 11:57:56 -07:00
Arnold Schwaighofer
ee6441c4d2 Fix test/Interop/Cxx 2021-08-05 12:15:23 -07:00
Egor Zhdan
a8f126f7cd C++ Interop: import const methods as non-mutating
This change makes ClangImporter import some C++ member functions as non-mutating, given that they satisfy two requirements:
* the function itself is marked as `const`
* the parent struct doesn't contain any `mutable` members

`get` accessors of subscript operators are now also imported as non-mutating if the C++ `operator[]` satisfies the requirements above.

Fixes SR-12795.
2021-07-25 15:18:33 +03:00
Egor Zhdan
36f13b7b91 C++ Interop: NFC: add missing requires cplusplus to the modulemaps in tests 2021-07-04 19:15:04 +03:00
Robert Widmann
2b9ad67029 Un-XFAIL a Passing Test on Windows 2021-04-20 17:14:56 -07:00
Egor Zhdan
9adad3202e C++ Interop: add tests for extensions of C++ classes 2021-04-16 20:25:57 +03:00
zoecarver
abab6b3332 [cxx-interop] Bail earlier when importing invalid records.
If we have a C++ record decl that's invalid (because of a deleted
destructor or copy constructor), bail before we import any of its
members or cache the decl. This way, we don't accidentally import any
"nested" decls.
2021-03-17 11:25:07 -07:00
zoecarver
655c381b32 [cxx-interop] Using shadow with class template.
Fail correctly if we can't import a shadow decl properly. We can
probably support this in the future, but right now, it's more important
that we don't crash while importing.
2021-03-07 10:55:38 -08:00
Zoe Carver
43c7ad7f46 Merge pull request #34864 from zoecarver/cxx/fix/friends
[cxx-interop] Support forward declared records inside other records.
2021-02-22 22:06:34 -08:00
zoecarver
f6a31e0483 [cxx-interop][nfc] Support forward declared records inside other records.
The pattern:

    struct X { friend struct Y; }; struct Y {};

is fairly common. But before this commit we would crash while attempting
to add "Y" as a child of "X". This commit simply checks if the child
record is a declaration or definition. If the former, it bails (and the
"child" record will be imported where it's defined).
2021-02-22 13:02:02 -08:00
zoecarver
467ff0a796 [nfc][gardening] Add requires cplusplus to LinkedRecords module. 2021-02-15 21:02:37 -08:00
Zoe Carver
6eb00d5c39 Merge pull request #35964 from zoecarver/cxx/another-double-add-fix
[cxx-interop] Skip already-imported sub decls.
2021-02-15 09:54:04 -08:00
zoecarver
bd96959d14 [cxx-interop] Re-implement namespaces using enums + extensions.
C++ namespaces are module-independent, but enums are owned by their module's in Swift. So, to prevent declaring two enums with the same name, this patch implements a new approach to namespaces: enums with extensions.

Here's an example:
```
// Module A
namespace N { void test1(); }
// Module B
namespace N { void test2(); }
// __ObjC module
enum N { }
// Swift module A
extension N { func test1() }
// Swift module B
extension N { func test1() }
```

Thanks to @gribozavr for the great idea.
2021-02-14 16:54:24 -08:00
zoecarver
fc33728613 [cxx-interop] Skip already-imported sub decls.
Rather than skipping non-definitions, we should just check whether we've
already seen this decl. This not only fixes the specific problem with
class templates but also is a more general fix for other sub decls.
2021-02-12 16:32:41 -08:00
Daniel Rodríguez Troitiño
182a011ec7 [android][test] XFAIL memory-layout-silgen in Android ARMv7 (#35816)
Change the original UNSUPPORTED to XFAIL, to get signal if the test
starts working.

PR #35707 should allow this test to work properly.
2021-02-07 16:30:03 -08:00
buttaface
e6f5913772 [android] Move to the NDK's unified sysroot (#34491)
Since the NDK removes the platforms/ and sysroot/ directories in the latest NDK
22, switch to the unified sysroot in toolchains/llvm/ and take advantage of a
bunch of simplification that's now possible.
2021-02-07 09:19:18 -08:00
Zoe Carver
74b7341b2d Merge pull request #32378 from zoecarver/cxx/copy-const
[cxx-interop] Use user defined copy constructor to copy C++ objects.
2021-02-03 22:39:57 -08:00
zoecarver
b2b7f7b853 [cxx-interop] Use user defined copy constructor to copy C++ objects.
If a user-defined copy constructor exists, use that to copy imported C++
types.
2021-02-03 14:34:07 -08:00
swift-ci
404c2bf085 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-28 13:32:22 -08:00
zoecarver
ffa0d1cf93 [cxx-interop] Add support for custom C++ destructors.
This patch adds support for custom C++ destructors. The most notable thing here, I think, is that this is the first place a struct type has a custom destructor. I suspect with more code we will expose a few places where optimization passes need to be fixed to account for this.

One of many patches to fix SR-12797.
2021-01-27 12:54:48 -08: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
swift-ci
e71625cff2 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-21 01:33:06 -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
swift-ci
4e05fc76ee Merge remote-tracking branch 'origin/main' into rebranch 2021-01-14 13:52:29 -08:00
Zoe Carver
9b0c17e363 Merge pull request #34869 from zoecarver/cxx/fix/forward-declared-with-child
[cxx-interop] Use cached record when possible.
2021-01-14 13:37:33 -08:00
zoecarver
ecd1018799 [cxx-interop] Use cached record when possible.
It is not completely uncommon for a record to get imported while
importing it's members (for example, if the member points back to the
parent record). In this case, simply use the already-imported record.
This should improve performance but also prevent an error where a member
accidentally had two parents.

This patch also moves around some of the member import/add logic to
allow for the above "optimization."
2021-01-13 11:19:36 -08:00
swift-ci
5e2c7dba68 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-13 09:12:39 -08:00
Saleem Abdulrasool
357face86e test: introduce new target-swiftxx-frontend for C++ interop
Add an convert to the new `target-swiftxx-frontend` substitution in lit
to control the C++ interop enabling in Swift.  This allows for a single
site which will enable control of both an overridden standard (for
testing multiple C++ standards) and simplify writing tests.
2021-01-12 11:45:36 -08:00
zoecarver
549189bee6 [cxx-interop] Add "nonnull" and "dereferenceable(n)" attributes to constructor params.
This reflects a change in Clang 13's codegen. Test-only fix for swift/rebranch.
2021-01-07 15:00:34 -08:00
swift_jenkins
62343a4d44 Merge remote-tracking branch 'origin/main' into next 2021-01-07 11:34:13 -08:00
Saleem Abdulrasool
df9d1e815f Interop/Cxx: explicitly require C++ for modules
The C++ interop modules require C++ support.  Explicitly require C++ as
a feature when building these modules.  This has no impact on the
changes as all the tests enable C++ already.
2021-01-06 16:59:42 -08:00
swift_jenkins
f979b095ae Merge remote-tracking branch 'origin/main' into next 2020-12-22 20:58:03 -08:00
zoecarver
8746d046a1 [cxx-interop] Define implict constructor on the definition.
Make sure that we define a C++ record's implicit constructor on the
record's definition, not just on a declaration.
2020-12-22 13:32:15 -08:00
zoecarver
7ac1b8121e [cxx-interop] Skip forward-declared nested structs.
This prevents us from accidentially adding the same sub-type twice.
2020-12-22 13:23:12 -08:00
swift_jenkins
fc33a461de Merge remote-tracking branch 'origin/main' into next 2020-12-15 00:46:51 -08:00
Marcel Hlopko
bde9c3b683 [cxx-interop] Fix header guards in test/Interop (#35039) 2020-12-15 09:20:19 +01:00
swift_jenkins
0b20fc3b0b Merge remote-tracking branch 'origin/main' into next 2020-12-08 16:42:26 -08:00
Arnold Schwaighofer
1f16f7ad8a Adjust to LLVM change that requires sret parameter attributes to be
annotated with the pointee type.

rdar://71808491
2020-12-03 09:39:41 -08:00
Butta
1a28a91db9 [android] Switch armv7 vendor to 'unknown' in target triple to match other arches
Recent changes have made 'none' and 'unknown' not interchangeable anymore, so
standardize on 'unknown' for armv7 too.
2020-12-02 11:05:36 +05:30
Zoe Carver
d048e0554a Merge pull request #34649 from zoecarver/cxx/no-import-no-destructor
[cxx-interop] Don't import C++ objects that we can't destroy.
2020-11-14 12:42:13 -08:00
Zoe Carver
b527bb5d3f Merge pull request #34730 from zoecarver/cxx/fix/nested-structs
[cxx-interop] Support nested C++ record types.
2020-11-14 12:41:08 -08:00
zoecarver
222d2fe709 [cxx-interop] Support nested C++ record types.
Simply returns "None" for C++ records in "getSpecialManglingContext"
(same logic as namespaces) to prevent an assertion.
2020-11-13 14:22:22 -08:00