Commit Graph

617 Commits

Author SHA1 Message Date
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
zoecarver
bcf8733c2b [cxx-interop] Don't import C++ objects that we can't destroy.
Don't import C++ objects unless they have a public destructor that is not deleted.
2020-11-13 13:18:12 -08:00
Zoe Carver
dfe92be435 Merge pull request #34424 from zoecarver/cxx/templated-constructors
[cxx-interop] Support templated constructors.
2020-11-11 12:10:38 -08:00
zoecarver
08e7160cec [cxx-interop] Support templated C++ constructors. 2020-11-11 09:38:10 -08:00
Robert Widmann
363b66a7ad Fully Qualify the Parent Type When Diagnosing Missing Member Types
Use the FullyQualified<Type> abstraction from the prior commit plus DescriptiveDeclKind to give a bit more information when issuing a missing member type diagnostic during type resolution.
2020-11-09 17:10:18 -08:00
Artem Chikin
3b545498d0 Merge pull request #34331 from artemcm/NoFoundationOnExplicitImportSoil
[Clang Importer] Do not rely on being able to always import Foundation on-demand
2020-11-02 13:02:15 -08:00
swift-ci
8ec7bdf634 Merge pull request #34429 from zoecarver/cxx/skip-unkown-constructor-names 2020-10-31 20:05:26 -07:00
Artem Chikin
e98dbc88fd Import Foundation in cxx interop tests that explicitly use/bridge its types 2020-10-29 10:37:01 -07:00
zoecarver
b7f656aa0d [cxx-interop] Use regex instead of operand name to fix C++ constructor tests. 2020-10-28 15:36:08 -07:00
Arnold Schwaighofer
6afe07d5f8 Disable two tests
rdar://70772958
2020-10-28 12:22:13 -07:00
zoecarver
d843279ea7 [cxx-interop] Bail instead of crashing If we cannot find a constructor decl in importNameImpl.
It's possible to have a "UnresolvedUsingValueDecl" with a "CXXConstructorName". If that's the case (or if there's any other unkown decl) bail instead of crashing.
2020-10-25 14:00:42 -07:00
zoecarver
d9acaf353e [cxx-interop] Merge synthesized initializer tests into "constructors-silgen".
We no longer synthesize initializers for C++ types so this name no longer makes sense.
2020-10-15 13:10:55 -07:00
zoecarver
1d3b051151 [cxx-interop] Remove logic around applying attributes.
Removes the logic around applying attributes to C++ constructor's
indirect results.

Also fixes some commenting.
2020-10-15 13:10:55 -07:00
zoecarver
b2bb47dee5 [cxx-interop] Fix Windows tests for non-trivial C++ types.
* Replace `??1` with `??0` prefix in SILGen tests.
* Replace `call void <constructor>` with `call {{.*}} <constructor>`
because Windows ABI sometimes returns a pointer from the constructor for
non-trivial types.
* Make `noalias` an optional check.
2020-10-15 13:10:55 -07:00
zoecarver
4364af39ee [cxx-interop] Small fixes and cleanup based on review.
* Check isAggregate instead of hasUserDeclaredConstructor.
 * Rename addEmptyArgNamesForCxxFunc ->  addEmptyArgNamesForClangFunction.
 * Other minor fixes and cleanups.
2020-10-09 10:42:54 -07:00
zoecarver
f04de9f128 [cxx-interop] Skip metatypes when lowering C++ constructor SIL function type.
When lowering a C++ constructor's function type to a SIL function type,
skip over the "self" metatype parameter.
2020-10-09 10:42:54 -07:00
zoecarver
2713edb19e [cxx-interop] Fix missing APIs and tests after rebase.
* Update tests that relied on old behavior.
 * Use mangleCXXName instead of mangleCXXCtor.
 * Call VisitCXXRecordDecl not VisitRecordDecl from
 VisitClassTemplateSpecializationDecl. This allows template constructors
 to be imported and called correctly.
2020-10-09 10:42:53 -07:00
Martin Boehme
cc7564ecd1 Rename constructors-sil.swift to constructors-silgen.swift. 2020-10-09 10:42:52 -07:00
Martin Boehme
83b51b95b5 Add SILGen and IRGen tests for passing Objective-C types to C++
constructors.
2020-10-09 10:42:52 -07:00
Martin Boehme
faca489c6f Add a test that Objective-C types passed to a C++ constructor are
bridged correctly.
2020-10-09 10:42:52 -07:00
Martin Boehme
7e8ea12070 Respond to review comments. 2020-10-09 10:42:51 -07:00
Martin Boehme
c9405fb7fc Add Windows-name-mangled version of symbol to SIL test. 2020-10-09 10:42:50 -07:00
Martin Boehme
8f6042aa08 Add additional IR tests for a class without a virtual base class. 2020-10-09 10:42:50 -07:00
Martin Boehme
8416ccfa06 Rename constructors-ir.swift to constructors-irgen.swift. 2020-10-09 10:42:50 -07:00
Martin Boehme
beaaa742c3 Don't put an sret attribute on the this argument. 2020-10-09 10:42:49 -07:00
Martin Boehme
bed2603944 Various changes after merging master:
- Adapt tests to changes that have happened in the meantime (e.g.
  `HasVirtualBase` is rightly no longer considered loadable)
- Don't import copy or move constructors (noticed this because
  references are now imported correctly, so copy and move constructors
  suddenly started showing up in the SIL test)
- Don't try to define an implicitly-deleted default constructor (this
  previously broke loadable-types-silgen.swift)
2020-10-09 10:42:49 -07:00
Martin Boehme
3066e16c37 Remove redundant "cxx" from test names. 2020-10-09 10:42:48 -07:00
Martin Boehme
b2c5a3eeed Add a constructor thunk if required to add additional constructor
arguments.

Also add more IR tests and make various other changes.
2020-10-09 10:42:48 -07:00
Martin Boehme
fd00bc1f01 Move tests from CXXInterop to Interop/Cxx.
This is the canonical location that we've agreed on.
2020-10-09 10:42:47 -07:00
Zoe Carver
aa5195aa89 Remove unneeded CHECK in type-classification-non-trivial-irgen. (#33474)
This CHECK line didn't use an alias, so it caused the CI to fail. It turns out the CHECK line isn't actually needed.
2020-08-14 09:28:15 -07:00
Zoe Carver
63875e9e8f [cxx-interop] [IRGen] TypeInfo for address-only types. (#32973)
The current "ClangRecordTypeInfo" derives from "LoadableTypeInfo" and is
only meant for loadable types. While we have not yet run into problems,
this may cause issues in the future and as more logic is needed around
copying, moving, and destroying C++ objects, this needs to be fixed.
2020-08-10 10:41:21 -07:00