Commit Graph

617 Commits

Author SHA1 Message Date
Akira Hatanaka
d76dbb1a64 [SILGen] Fix a bug where the wrong convention was being used for lowering a closure to a C++ function pointer (#73039)
Use the C function pointer convention instead of the block convention.

rdar://122977380
2024-04-16 15:18:50 -07:00
Egor Zhdan
bac5d0e9a1 [cxx-interop] Zero-initialize C++ structs when calling their default constructors
When Swift imports C structs, it synthesizes an initializer that takes no arguments and zero-initializes the C struct.

When C++ interop is enabled, Clang treats all C structs as if they were C++ structs. This means that some of the C structs will get a default constructor implicitly generated by Clang. This implicit default constructor will not zero-initialize trivial fields of the struct.

This is a common source of confusion and subtle bugs for developers who try to enable C++ interop in existing projects that use C interop and rely on zero-initialization of C structs.

rdar://115909532
2024-04-16 13:42:02 +01:00
Egor Zhdan
802f20ec00 [cxx-interop][IRGen] Assign Clang function types to copy constructors
This fixes an assertion failure when building certain projects for arm64e with `-use-clang-function-types` Swift compiler flag:
```
Expected non-null Clang type for @convention(c)/@convention(block) function but found nullptr
```

rdar://121227452
2024-04-03 19:26:32 +01:00
Egor Zhdan
1be7230876 [cxx-interop] Use C++17 standard by default
Clang is using C++17 standard version by default since Clang 16.

Swift’s ClangImporter should do the same, to make sure that clients who run clang and then swiftc without explicit std version see consistent behavior.

rdar://125777068
2024-04-02 16:23:32 +01:00
Karoy Lorentey
9725b892cc [test] More test updates 2024-03-18 13:27:46 -07:00
Kavon Farvardin
2951162527 Test: disable move-only-cxx-value-type.swift
The test was relying on UnsafeMutablePointer (UMP) not having a Copyable
 requirement. Those Copyable requirements are more prominent when using
the new infrastructure for noncopyable types. Since UMP is planned to
have `~Copyable` on its generic parameter quite soon, this shouldn't
remain broken for too long.
2024-03-14 23:10:44 -07:00
Egor Zhdan
2c6cc4a6e5 Merge pull request #72186 from apple/egorzhdan/swift-bridging-modulemap
[cxx-interop] Refer to `SwiftBridging` module from `usr/include/module.modulemap`
2024-03-11 19:01:33 +00:00
Nate Chandler
dff0b2efaa [SILGen] Allocs for VDs are var_decl.
Annotate alloc_stack instructions that correspond to VarDecls with the
var_decl flag.
2024-03-08 22:28:22 -08:00
Egor Zhdan
d494632e98 [cxx-interop] Refactor: move swift/bridging source elsewhere for better testability
rdar://123334601
2024-03-08 20:13:27 +00:00
Doug Gregor
59d1846b59 De-XFAIL a test that now works with noncopyable generics 2024-03-07 15:32:13 -08:00
Egor Zhdan
b19ca43a43 [cxx-interop] Fix virtual method tests on non-macOS 2024-03-03 00:49:45 +00:00
Egor Zhdan
8ead7224b7 [cxx-interop] Overhaul virtual method support
This adds a new implementation of virtual method dispatch that handles reference types correctly.

Previously, for all C++ types an invocation of a virtual method would actually get dispatched statically. For value types this is expected and matches what C++ does because of slicing. For reference types, however, this is incorrect, we should do dynamic dispatch.

rdar://123852577
2024-03-01 19:45:58 +00:00
Egor Zhdan
d3a0bf4ea8 Merge pull request #71836 from apple/egorzhdan/cxx-tests-swift-6
[cxx-interop] Run tests with `swift-6` compat mode
2024-02-26 10:52:03 +00:00
Doug Gregor
0c9c734f7e Merge pull request #71722 from DougGregor/diagnostic-style-swift-default 2024-02-24 14:42:38 -10:00
Egor Zhdan
78b9de1391 [cxx-interop] Run tests with swift-6 compat mode 2024-02-23 16:24:14 +00:00
Akira Hatanaka
b3f302b96b [IRGen] Fix a bug where an argument wasn't annotated with sret (#71459)
Fix a bug in expandExternalSignatureTypes where it wasn't annotating a function call parameter type with sret when the result was being returned indirectly.

The bug was causing calls to ObjC methods that return their results indirectly to crash.

Additionally, fix the return type for C++ constructors computed in expandExternalSignatureTypes. Previously, the return type was always void even on targets that require constructors to return this (e.g., Apple arm64), which was causing C++ constructor thunks to be emitted needlessly.

Resolves rdar://121618707
2024-02-22 14:14:47 -08:00
Akira Hatanaka
97a814805a [IRGen] Make sure a C++ constructor thunk is called when it's needed (#71790)
This fixes a bug where the thunk for a C++ constructor call wasn't being
called when the constructor was called the second time.
2024-02-22 07:05:07 -08:00
Alex Lorenz
6312fc05cc [interop] adopt a swift-6 interoperability mode for new features in the next release 2024-02-21 09:27:45 -08:00
Kavon Farvardin
f296d8e158 NCGenerics: mass XFAIL tests
It's easier to get a handle on regressions while working through
failures if the tests that are known to not pass are XFAIL'd for
NoncopyableGenerics.
2024-02-20 18:26:05 -05:00
Doug Gregor
8cd2f34654 Generalize tests for both diagnostic styles, or force the LLVM style
These tests are using FileCheck to check the result of diagnostic
formatting in ways that don't match the new formatter. Force the old
formatter or, where possible, generalize so that they match both
formatters.
2024-02-19 02:48:37 -10:00
Ikko Eltociear Ashimine
0c1ffb1a21 Fix typo in runtime-polymorphism.swift
comparision -> comparison
2024-02-19 00:49:30 +09:00
Kavon Farvardin
08b71e0136 NCGenerics: rebuild stdlib from its interface
When a NoncopyableGenericsMismatch happens between the compiler and
stdlib, allow the compiler to rebuild the stdlib from its interface
instead of exiting with an error.
2024-02-15 18:08:54 -08:00
Guillaume Lessard
114f235d17 Merge pull request #71167 from vanvoorden/vanvoorden/inclusive-language
[Inclusive Language][Comments][Documentation] migrate "sanity" checks to "soundness" checks
2024-02-02 10:27:34 -08:00
Kavon Farvardin
5f977ca763 NCGenerics: force module mismatches 2024-01-31 14:00:08 -08:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Allan Shortlidge
bb38de355b Add REQUIRES: asserts to NoncopyableGenerics tests. 2024-01-11 15:31:40 -08:00
Egor Zhdan
53979a2fcc [cxx-interop] More tests for move-only C++ types 2024-01-08 17:13:47 +00:00
Egor Zhdan
35e474d5d6 [cxx-interop] NFC: Remove leftover comment 2024-01-08 15:40:01 +00:00
Akira Hatanaka
14cfebc640 Fix a crash in ClangImporter::Implementation::DiagnosticWalker::TraverseDecl
The call to `D->getBeginLoc` crashes when `D` is null.

rdar://118899818
2023-12-19 15:58:42 -08:00
Egor Zhdan
233b80e431 Merge pull request #70503 from apple/egorzhdan/no-abstract-ctors
[cxx-interop] Do not import constructors of abstract C++ classes
2023-12-18 17:24:00 +00:00
Egor Zhdan
325868808b [cxx-interop] Do not import constructors of abstract C++ classes
Clang rejects code that tries to call a constructor of an abstract C++ class with an error: "Variable type 'Base' is an abstract class". Swift should reject this as well.

rdar://119689243
2023-12-18 14:52:32 +00:00
Alex Lorenz
9261fa765d Merge pull request #70420 from hyp/eng/virtual-methods++
[cxx-interop] virtual method fixes
2023-12-16 06:37:44 -08:00
Egor Zhdan
73cf3be98c [cxx-interop] Do not import CxxShim explicitly in tests 2023-12-15 19:51:41 +00:00
Alex Lorenz
72db47239b [cxx-interop] enable the virtual methods irgen test on windows 2023-12-13 14:33:09 -08:00
Alex Lorenz
c19ea96809 [interop] allow virtual methods only for the 'upcoming-swift' release 2023-12-12 17:20:53 -08:00
Egor Zhdan
6ecaaa41c5 Merge pull request #70304 from apple/egorzhdan/conforms-to-derived-class
[cxx-interop] Propagate `CONFORMS_TO` attribute to derived classes
2023-12-07 22:00:44 +01:00
Egor Zhdan
45b22542d5 [cxx-interop] Propagate CONFORMS_TO attribute to derived classes
If `struct Base` is a public base class of `struct Derived`, and `Base` is annotated with `__attribute__((swift_attr("conforms_to:MyModule.MyProto")))`, `Derived` will now also get a conformance to `MyProto`.

rdar://113971944
2023-12-07 18:11:37 +00:00
Alex Lorenz
c7345d08cf Merge pull request #69790 from hyp/eng/move-only-is-back
[cxx-interop] enable support for move-only types
2023-12-06 09:43:43 -08:00
Alex Lorenz
623d3d2032 [cxx-interop] review fixes for non-copyable patch, ensure we only enable this in upcoming Swift 2023-12-05 14:16:30 -08:00
Alex Lorenz
ec931c82c4 [cxx-interop] non-copyable test windows workaround and no SIL verify for NC generic test 2023-12-05 13:42:13 -08:00
Puyan Lotfi
128064f31d [cxx-interop] Enable virtual function calling from Swift to C++
This is a forward-interop feature that wires up existing functionality for
synthesizing base class function calling to enable virtual function calling.
The general idea is to sythesize the pattern:

```
// C++ class:
struct S { virtual auto f() -> int { return 42; } };

// Swift User:
var s = S()
print("42: \(s.f())")

// Synthetized Swift Code:
extension S { func f() -> CInt { __synthesizedVirtualCall_f() } }

// Synthetized C/C++ Code:
auto __cxxVirtualCall_f(S *s) -> int { return s->f(); }
```

The idea here is to allow for the synthetized C++ bits from the Clang side to
handle the complexity of virtual function calling.
2023-12-04 01:55:30 -05:00
Alex Lorenz
3a340c78f0 [cxx-interop] move-only: do not test consume with unsafeAddress accessors - they do not yet work 2023-12-03 18:11:07 -08:00
Alex Lorenz
580ecd0893 [cxx-interop] fix Egor's review comments for move-only patch 2023-11-30 10:12:11 -08:00
Alex Lorenz
b7158ea486 [cxx-interop] add SWIFT_NONCOPYABLE annotation 2023-11-29 18:13:31 -08:00
Alex Lorenz
6a47011b18 [cxx-interop] add IRGen test for field base accessors for non-copyable fields 2023-11-29 09:10:51 -08:00
Alex Lorenz
bacc58e0f7 [cxx-interop] provide correct referential access to non-copyable base fields from a derived value type 2023-11-28 20:10:07 -08:00
Alex Lorenz
51d0e84933 [cxx-interop] add a test to cover accessing non-copyable field 2023-11-28 14:07:44 -08:00
Alex Lorenz
fd6a5a20ef [cxx-interop] test accessing fields of a move-only C++ type 2023-11-28 12:26:48 -08:00
Hiroshi Yamauchi
897fae2b26 Merge pull request #69929 from hjyamauchi/methods-this-and-indirect-return-irgen-msvc
Fix test methods-this-and-indirect-return-irgen-msvc.swift for windows/aarch64
2023-11-27 10:54:05 -08:00
Hiroshi Yamauchi
e59fcc46dd Fix test methods-this-and-indirect-return-irgen-msvc.swift for windows/aarch64
Handle a slight LLVM IR difference in the second parameter (inreg) of
a function between x86_64 and aarch64. These are how Clang on windows
emits the code.
2023-11-16 13:34:36 -08:00