Commit Graph

597 Commits

Author SHA1 Message Date
swift-ci
6dc53cce15 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-24 11:14:58 -07:00
eeckstein
4285d8a87c Revert "[cxx-interop] Add test for lifetimebound annotation in ctor" 2024-09-24 20:00:37 +02:00
Gabor Horvath
cbd8cdfe95 [cxx-interop] Add rules to recognize escapability of aggregates
For now, this logic is used for importing fewer unannotated types as
unsafe. In the future, this logic will be used by escapability inference
for other (non-aggregate) types.
2024-09-24 16:41:00 +01:00
swift-ci
2bd533ccda Merge remote-tracking branch 'origin/main' into rebranch 2024-09-24 07:55:58 -07:00
Gábor Horváth
40529912a9 Merge pull request #76668 from swiftlang/gaborh/lifetimebound-off-by-one
[cxx-interop] Fix off-by-one error when importing lifetimebound attrs
2024-09-24 15:49:19 +01:00
Gábor Horváth
289a4f5e35 Merge pull request #76653 from swiftlang/gaborh/unsafe_reference
[cxx-interop] Import SWIFT_UNSAFE_REFERENCE types as @unsafe
2024-09-24 15:48:45 +01:00
Gabor Horvath
72ce39ce07 [cxx-interop] Fix off-by-one error when importing lifetimebound attrs 2024-09-24 12:01:26 +01:00
Gabor Horvath
e8aea32c95 [cxx-interop] Import SWIFT_UNSAFE_REFERENCE types as @unsafe 2024-09-23 16:51:01 +01:00
Gabor Horvath
8c3849b192 [cxx-interop] Add test for lifetimebound annotation in ctor
It looks like everything worked out of the box, no code changes
required. Added a test to avoid regressions.
2024-09-23 16:06:44 +01:00
swift-ci
df338c19a8 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-19 09:34:45 -07:00
Gabor Horvath
929c0ca7d8 [cxx-interop] Introduce a safe C++ interop mode
In this mode all C++ types are imported as unsafe by default. Users
explicitly marking types are escapable or not escapable can make them
imported as safe. In the future, we also want to import unannotated
functions as unsafe and add more logic to infer types that are actually
safe, like agregates of escapable types.
2024-09-19 12:34:07 +01:00
swift-ci
72a4f929b0 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-18 07:33:29 -07:00
Gábor Horváth
ffa1014c30 Merge pull request #76311 from swiftlang/gaborh/import-lifetimebound
[cxx-interop] Teach importer to interpret lifetimebound annotations
2024-09-18 15:24:32 +01:00
Gabor Horvath
16e012bb5e [cxx-interop] Teach importer to interpret lifetimebound annotations
The lifetimebound annotations are now imported as lifetime dependencies.
This works for basic cases but there are still some parts missing:
* Support lifeitmebound annotations on constructors
* A way to represent immortal/static lifetimes on the C++ side
2024-09-18 10:51:05 +01:00
Ben Barham
a7b50f357f Merge remote-tracking branch 'origin/main' into manual-main-merge
Conflicts:
  - `lib/Driver/ToolChains.cpp` conflicting with the `addAllArgs` rename
    for multiple options
2024-09-16 13:53:18 -07:00
Hiroshi Yamauchi
7633c00764 Merge pull request #76433 from hjyamauchi/issue74866-2
Ensure that BridgedTypeArray is indirectly returned
2024-09-16 11:46:29 -07:00
Hiroshi Yamauchi
f815e1429e Ensure that BridgedTypeArray is indirectly returned
On Windows ARM64, how a struct value type is returned is sensitive to
conditions including whether a user-defined constructor exists,
etc. See

https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#return-values

That caused a calling convention mismatch between the
non-USED_IN_CPP_SOURCE (Swift) side and the USE_IN_CPP_SOURCE (C++)
side and a crash.

Add this constructor so that the calling convention matches.

This is a fix for the OnoneSimplification crash in

https://github.com/swiftlang/swift/issues/74866#issuecomment-2319618579

and is a partial fix for

https://github.com/swiftlang/swift/issues/74866#issuecomment-2319618579
2024-09-12 10:46:55 -07:00
Akira Hatanaka
380f319371 Relax check strings (#76421)
rdar://135165028
2024-09-12 10:35:36 -07:00
Alex Lorenz
9bc2689ef1 [rebranch][cxx-interop] fix MSVC testcase check line for indirect return 2024-09-10 09:37:07 -07:00
Akira Hatanaka
7aaed1efea Pass --dump-input-filter=all to debug failing test (#76333) 2024-09-09 10:47:31 -07:00
swift-ci
93b400de6d Merge remote-tracking branch 'origin/main' into rebranch 2024-09-05 14:14:34 -07:00
Hiroshi Yamauchi
273f5fdc36 Merge pull request #76159 from hjyamauchi/issue74866
Add the inreg attribute to sreg when present.
2024-09-05 13:59:53 -07:00
Hiroshi Yamauchi
3f0de5787e Add the inreg attribute to sreg when present.
On Windows/AArch64, a different register is used between when an
arugment is both inreg and sret (X0 or X1) and when it is just sret
(X8) as the following comment indicates:

46fe36a429/llvm/lib/Target/AArch64/AArch64CallingConvention.td (L42)

```
  // In AAPCS, an SRet is passed in X8, not X0 like a normal pointer parameter.
  // However, on windows, in some circumstances, the SRet is passed in X0 or X1
  // instead.  The presence of the inreg attribute indicates that SRet is
  // passed in the alternative register (X0 or X1), not X8:
  // - X0 for non-instance methods.
  // - X1 for instance methods.

  // The "sret" attribute identifies indirect returns.
  // The "inreg" attribute identifies non-aggregate types.
  // The position of the "sret" attribute identifies instance/non-instance
  // methods.
  // "sret" on argument 0 means non-instance methods.
  // "sret" on argument 1 means instance methods.

  CCIfInReg<CCIfType<[i64],
        CCIfSRet<CCIfType<[i64], CCAssignToReg<[X0, X1]>>>>>,

  CCIfSRet<CCIfType<[i64], CCAssignToReg<[X8]>>>,
```

So missing/dropping inreg can cause a codegen bug.

This is a partial fix for #74866
2024-09-04 18:00:36 -07:00
swift-ci
8fc7ad929f Merge remote-tracking branch 'origin/main' into rebranch 2024-09-04 17:14:41 -07:00
Akira Hatanaka
f81d2e67f7 Fix a test that was failing on armv7k (#76259)
rdar://135165028
2024-09-04 17:06:20 -07:00
swift-ci
ec365a63eb Merge remote-tracking branch 'origin/main' into rebranch 2024-09-03 19:55:40 -07:00
Akira Hatanaka
7cdbb64567 Disable test on arm64e (#76229)
rdar://135165028
2024-09-03 19:51:32 -07:00
swift-ci
f1877410ef Merge remote-tracking branch 'origin/main' into rebranch 2024-09-03 02:53:13 -07:00
Gabor Horvath
738b4c6d8d [cxx-interop] Add a SWIFT_NONESCAPABLE attribute to the bridging header
This makes it easier to experiment with noescapable types in interop.
Moreover, we always wanted to have this annotation for completeness,
similar to SWIFT_NONCOPYABLE.
2024-09-02 14:51:27 +01:00
swift-ci
1b23f6a9b2 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-29 20:55:52 -07:00
Akira Hatanaka
5bd7a27e96 [cxx-interop] Do not over-release objects returned by synthesized C++ methods (#76139)
Call Sema::BuildReturnStmt instead of ReturnStmt::Create so that an
implicit cast of kind ARCProduceObject is inserted in the AST.

rdar://133731973
2024-08-29 20:45:16 -07:00
swift-ci
4d062ca332 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-28 09:53:27 -07:00
Alexander Cyon
db0b5db54e [test/Interop] Fix typos (#75032) 2024-08-28 09:41:09 -07:00
Egor Zhdan
fc4f6480a8 [cxx-interop][rebranch] Do not crash for static operator()
This fixes an assertion failure:
```
Assertion failed: (isInstance() && "No 'this' for static methods!"), function getThisType, file DeclCXX.cpp, line 2636.
```

Clang changed it's handling of member call expressions in af4751738d causing the assertion to fail when synthesizing a forwarding function declaration for `static operator()`.

rdar://133257179
2024-08-15 16:31:17 +01:00
Ben Barham
df81d0a450 [Tests] XFAIL the remaining test failures on rebranch
Only a few tests remaining. XFAIL so we can test the rest of the
toolchain.
2024-08-08 14:47:18 -07:00
Alex Hoppen
66104395d7 [Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
Some editors use diagnostics from SourceKit to replace build issues. This causes issues if the diagnostics from SourceKit are formatted differently than the build issues. Make sure they are rendered the same way, removing most uses of `DiagnosticsEditorMode`.

To do so, always emit the `add stubs for conformance` note (which previously was only emitted in editor mode) and remove all `; add <something>` suffixes from notes that state which requirements are missing.

rdar://129283608
2024-08-07 14:01:30 -07:00
Akira Hatanaka
658de4ae65 Fix a test that was failing on arm64e (#75550)
rdar://130759216
2024-07-29 20:39:24 -07:00
Andrew Trick
030f2b8e90 Merge pull request #75050 from atrick/vardecl_lifetime
[SILGen] Create SIL variable declaration scopes for trivial values.
2024-07-26 16:23:07 -07:00
Andrew Trick
a1fe258692 Update tests for new trivial moves and extend_lifetimes. 2024-07-26 08:27:48 -07:00
Finagolfin
15e1c73969 [android][test] Enable several C++ Interop and other tests
Also, fix lit.cfg for running the test suite natively in Android and mark one
SILOptimizer executable_test as such.
2024-07-20 17:56:51 +05:30
Gábor Horváth
e836e2caeb Merge pull request #75176 from swiftlang/gaborh/inheritance-2
[cxx-interop] Fix wrong field offsets with value types using inheritance
2024-07-18 03:59:47 -07:00
Gabor Horvath
d0e6d2f426 [cxx-interop] Fix input header paths in a test
rdar://131629163
2024-07-15 12:00:17 +01:00
Gabor Horvath
ce3fa734ce [cxx-interop] Fix wrong field offsets with value types using inheritance
Instead of adding opaque fields for the base subobjects this patch
introduces a recursive walk to add all the base fields to the generated
Swift struct.

rdar://126754931
2024-07-11 17:20:18 +01:00
Egor Zhdan
14f39beca0 Merge pull request #75058 from swiftlang/egorzhdan/attrs-clone
[cxx-interop] Clone all of the attributes from base method correctly
2024-07-09 11:47:18 +01:00
Egor Zhdan
b50955144e [cxx-interop] Clone all of the attributes from base method correctly
If a C++ `struct Base` declares a method with a Clang attribute that Swift is able to import, and `struct Derived` inherits from `Base`, the method should get cloned from `Base` to `Derived` with its attributes.

Previously we were only cloning one attribute at most due to a bug in `cloneImportedAttributes`. DeclAttributes is an intrusively linked list, and it was being made invalid while iterating over it: `otherDecl->getAttrs().add(attrs)` iterates over the list and calls `otherDecl->add(eachElement)`, which invalidates the iterator after the first iteration.
2024-07-08 15:48:20 +01:00
Egor Zhdan
daaec01d29 [cxx-interop] Adjust another IRGen test for rebranch
This fixes `Interop/Cxx/class/method/methods-this-and-indirect-return-irgen-itanium.swift` by adjusting the expected function signature.

On rebranch, the actual signature is:
```
define linkonce_odr void @_ZN10HasMethods28nonConstPassThroughAsWrapperEi(ptr dead_on_unwind noalias writable sret(%struct.NonTrivialInWrapper) align 4 %agg.result, ptr noundef nonnull align 1 dereferenceable(1) %this, i32 noundef %a)
```

rdar://127263407
2024-07-08 13:51:33 +01:00
Egor Zhdan
d8e8216895 [cxx-interop] Adjust an IRGen test for rebranch
This fixes `Interop/Cxx/class/returns-large-class-irgen.swift` by adjusting the expected function signature.

On rebranch, the actual signature is:
```
define void @_Z21funcReturnsLargeClassv(ptr dead_on_unwind noalias writable sret(%struct.LargeClass) align 8 %agg.result)
```

rdar://127263407
2024-07-08 13:44:23 +01:00
Egor Zhdan
34c796d100 [cxx-interop] Add a test for instantiation of a default destructor
This is a follow-up to f56fa41.

rdar://124061505
2024-07-04 17:35:01 +01:00
Akira Hatanaka
1b38ca929d Remove reference to attribute group in test (#74816)
rdar://130759216
2024-06-28 16:18:23 -07:00
Akira Hatanaka
42bc49d3fe Add a new parameter convention @in_cxx for non-trivial C++ classes that are passed indirectly and destructed by the caller (#73019)
This corresponds to the parameter-passing convention of the Itanium C++
ABI, in which the argument is passed indirectly and possibly modified,
but not destroyed, by the callee.

@in_cxx is handled the same way as @in in callers and @in_guaranteed in
callees. OwnershipModelEliminator emits the call to destroy_addr that is
needed to destroy the argument in the caller.

rdar://122707697
2024-06-27 09:44:04 -07:00