Commit Graph

2546 Commits

Author SHA1 Message Date
Doug Gregor
cd0380b646 [Clang importer] Import Clang swift_attr attribute.
The Clang swift_attr attribute allows C code to describe, via a Clang
attribute, the Swift attributes that should be applied to the given
declaration. When an

    __attribute__((__swift_attr__("@tribute")))

occurs on a Clang declaration, parse the attribute within the string
literal as a Swift attribute, then attach that to the imported Swift
declaration.

Fixes rdar://70146633.
2021-01-08 12:08:45 -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
fbcb0e2d44 Merge remote-tracking branch 'origin/main' into next 2020-12-05 10:41:51 -08:00
Zoe Carver
8104d5ffbf Merge pull request #34956 from zoecarver/cxx/cache-nullptr
[gardening] Remove uses of "importDeclCached" and cleanup "VisitEnumConstantDecl".
2020-12-05 10:35:47 -08:00
swift_jenkins
8351c9dbf3 Merge remote-tracking branch 'origin/main' into next 2020-12-04 13:03:17 -08:00
zoecarver
3ac7dbf7bb [gardening] Remove uses of "importDeclCached" and cleanup "VisitEnumConstantDecl".
Cleans up the EnumConstantDecl visitor by consolidating cases and
removing calls to "importDeclCached".
2020-12-03 21:36:04 -08:00
zoecarver
c4363b916f [cxx-interop] Support class template specializations in namespaces.
This just changes an assertion and adds a test.
2020-12-03 12:13:07 -08:00
swift_jenkins
6e2b4b23ea Merge remote-tracking branch 'origin/main' into next 2020-12-01 10:17:48 -08:00
Zoe Carver
2b0ff64fdb Merge pull request #34870 from zoecarver/cxx/fix/no-params
[cxx-interop] Bail on functions that use unimportable types.
2020-12-01 10:12:20 -08:00
swift_jenkins
777e1a9698 Merge remote-tracking branch 'origin/main' into next 2020-11-30 15:14:27 -08:00
zoecarver
3d6c8a7971 [cxx-interop] Fix assertion to allow variadic members.
Simply fixes an assertion to allow variadic member functions.
2020-11-30 11:55:56 -08:00
zoecarver
6e69918a18 [cxx-interop] Bail on functions that use unimportable types.
We already fixed this for "global" functions. This is a more generic
solution that works for "nested" functions as well. (Members or
functions in a namespace.)
2020-11-24 12:59:58 -08:00
swift_jenkins
48e4ee6966 Merge remote-tracking branch 'origin/main' into next 2020-11-18 07:22:44 -08:00
Doug Gregor
c7c0fedb4a [Clang importer] Narrow mirrored-import fixes to only consider 'async'.
The previous change was too broad and caused several regressions.
2020-11-17 23:48:23 -08:00
Doug Gregor
d249b5cce5 [Clang importer] Make sure we mirror protocol decls for all names.
When mirroring declarations from protocols, make sure to mirror for
all potential imported names. Otherwise, we might miss out on one or
the other of an async import or a completion-handler import of the
same method.

Fixes rdar://71429577.
2020-11-17 22:26:41 -08:00
swift_jenkins
8b7e62dcf6 Merge remote-tracking branch 'origin/main' into next 2020-11-14 12:52:24 -08:00
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
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
swift_jenkins
332645899e Merge remote-tracking branch 'origin/main' into next 2020-11-10 22:43:49 -08:00
zoecarver
9c58a95755 [cxx-interop] Support function templates inside a namespace.
Thread "templateParams" through the call to find the function parameter
types when the function is in a namespace.
2020-11-10 18:49:51 -08:00
swift_jenkins
fa7aebcf67 Merge remote-tracking branch 'origin/main' into next 2020-11-05 22:33:58 -08:00
Zoe Carver
88a6f15dd2 [re-apply][cxx-interop] Support class templates containing typedefs. (#34601)
This prevents an assertion in "isOverAligned" caused class templates
that contain and use typedefs.

Re-landing 7f2b0aad2b after being reverted
in 5ef0136356.
2020-11-05 21:54:19 -08:00
swift_jenkins
95d48468e6 Merge remote-tracking branch 'origin/main' into next 2020-11-05 10:37:53 -08:00
Saleem Abdulrasool
5ef0136356 Revert "[cxx-interop] Support class templates containing typedefs." 2020-11-05 07:55:24 -08:00
swift_jenkins
ca7db980ec Merge remote-tracking branch 'origin/main' into next 2020-11-04 22:35:34 -08:00
Arnold Schwaighofer
97e5e01fe2 Merge remote-tracking branch 'origin/main' into next 2020-11-04 12:20:35 -08:00
zoecarver
7f2b0aad2b [cxx-interop] Support class templates containing typedefs.
This prevents an assertion in "isOverAligned" caused class templates
that contain and use typedefs.
2020-11-02 23:17:34 -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_jenkins
fa32dc6ba7 Merge remote-tracking branch 'origin/main' into next 2020-10-30 00:09:25 -07:00
John McCall
e35f077a9b Merge pull request #33349 from ellishg/master
[IRGen] Call objc_direct methods correctly
2020-10-30 03:03:54 -04:00
Artem Chikin
0305f20f32 [Clang Importer] Do not rely on being able to always import Foundation on-demand
When importing Clang types.
This is not an option with Explicit Module Builds. If the module being built does not (directly or transitively) depend on `Foundation`, then attempting to load it will produce an error because Implicit module loading is no longer allowed..

This change addresses a small number of cases where ClangImporter relies on being able to load `Foundation` on-demand:
- When importing a single Decl from a clang module, we check whether it has certain conformances by checking all extensions of the NominalTypeDecl of the Decl in question, to see if any of the extensions contain the conformance we are looking for, but we only check extensions whose parent module is either the original module of the NominalTypeDecl or the overlay module of the NominalTypeDecl or Foundation. It seems that we do not need to actually import `Foundation` here, just checking the module Identifier should be sufficient.
- In `maybeImportNSErrorOutParameter`, change the behavior to have an exit condition based on whether `Foundation` can be imported, before attempting to load it.
- When checking whether or not we are allowed to bridge an Objective-C type, it also looks sufficient the query whether or not `Foundation` *can* be imported, without loading it.
2020-10-28 14:47:17 -07:00
David Smith
0180aca9fc Merge branch 'main' into david/fix-merge-conflict 2020-10-27 13:05:20 -07:00
swift-ci
38d759c43a Merge pull request #34428 from zoecarver/cxx/empty-template-spec 2020-10-26 16:01:27 -07:00
swift-ci
26c962629f Merge pull request #34365 from zoecarver/cxx/bool-enum 2020-10-26 15:57:42 -07:00
zoecarver
3a87cbefad [cxx-interop] Disable importing fully specialized class templates.
Before this patch we would crash when importing a fully specialized
class template contianing a child declaration. This patch simply bails
on fully-specialized class templates instead of potentially crashing.
2020-10-25 13:06:41 -07:00
zoecarver
05faa07c48 [cxx-interop] Support bool-based enums.
This is a small fix to prevent a crash. This change simply adds another
condition for the "bool" branch that checks if "type" is associated with
a "clang::EnumDecl" with an underlying type of "bool", and if so, treats
"type" as a "Bool".
2020-10-24 23:08:59 -07:00
Ellis Hoag
3aa081c56e [IRGen] Call objc_direct methods correctly 2020-10-23 11:54:07 -05:00
Saleem Abdulrasool
4a8948373e ClangImporter: support the MS anonymous structure extension
The Microsoft extension permits the creation of structures without a
name which effectively create an anonymous inline structure.  Accommodate
that in the ClangImporter.

For more details about the extension, see:
https://docs.microsoft.com/en-us/previous-versions/a3bbz53t(v=vs.140)#anonymous-structs

Thanks to @brentdax for the suggestion of the additional check!
2020-10-22 15:43:10 -07:00
Zoe Carver
f0f2246793 [cxx-interop] Support C++ function templates in Swift. (#33053)
This patch adds rudimentary support for C++ template functions in swift.
2020-10-21 20:42:25 -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
swift_jenkins
25160da347 Merge remote-tracking branch 'origin/main' into next 2020-10-14 13:47:25 -07:00
Alexis Laferrière
e509d6883a Revert "[Sema] Fix availability checking in inlinable code" 2020-10-14 10:52:11 -07:00
swift_jenkins
8fddbcef4d Merge remote-tracking branch 'origin/main' into next 2020-10-13 09:16:15 -07:00
zoecarver
4cb337a41f [cxx-interop] Generate memberwise initializers for non-C++ types.
Previously, when we checked for `!hasUserDeclaredConstructor` rather than
`isAggregate`, we would always generate memberwise initializers for C
record types. This updates the isAggregate to be true for non-C++ types
so we will generate memberwise initializers for them as well.
2020-10-10 15:08:30 -07:00
Alexis Laferrière
429017fc7a [ClangImporter] Import unavailable decls as unavailable 2020-10-09 10:57:01 -07:00
zoecarver
5774610eaf [cxx-interop] Fix patch formatting with clang-format.
Fix all formatting of the changes made by this patch.
2020-10-09 10:42: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
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