Commit Graph

99 Commits

Author SHA1 Message Date
swift-ci
61d5b48a52 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-02 08:15:55 -07:00
Egor Zhdan
fcb590690e [cxx-interop] Support char8_t C++20 type
https://en.cppreference.com/w/cpp/keyword/char8_t

This is based on a patch from Varun Gandhi: https://github.com/swiftlang/swift/pull/26153

rdar://39988329 / resolves https://github.com/swiftlang/swift/issues/68726
2024-09-27 13:56:03 +01:00
Xi Ge
736ccef626 Merge remote-tracking branch 'apple/main' into rebranch 2024-06-20 15:16:55 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ben Barham
a4367131a7 [ClangImporter] Update moved isSimpleTypeSpecifier reference
Moved from `Sema` to `Token` in LLVM
a8279a8bc541b6027087dd497daa63b6602b7f4b.
2024-04-08 08:58:59 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
zoecarver
7216be13fa [cxx-interop] A little macros fix; breadcrumbs for future fixes. 2023-06-22 12:21:10 -07:00
Becca Royal-Gordon
ced4cb0681 Handle out-of-date identifiers in macros
After adopting the stable/20221013 clang branch, ClangImporter started seeing out-of-date identifiers in macros where it previously never had. Force these identifiers to update themselves before we read the macro definition out of them.

Fixes rdar://104456939.
2023-01-26 14:01:21 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03:00
Egor Zhdan
1839ddb115 [ClangImporter] NFC: extract Swift decl synthesis logic into a separate file
`ImportDecl.cpp` contained 10k+ lines of code, which caused slowdowns in incremental compilation and while editing the code in the IDE.

This change extracts a chunk of largely self-contained decl synthesis logic into a separate file.
2022-06-17 16:52:18 +01:00
Becca Royal-Gordon
192c52ff17 [NFC] Integrate ImportTypeAttrs into importType() 2022-03-29 17:18:09 -07:00
Becca Royal-Gordon
6f71581b5c [NFC] Thread import diagnostics through ImportType
`ClangImporter::Implementation::importType()` and associated parts of the importer are now passed an `llvm::function_ref` they can use to emit import diagnostics on the declaration they’re importing, and the `ImportDiagnosticAdder` helper class provides a convenient way to construct such a function.

This capability is not actually *used* in this commit—we are simply threading this function through the importer—so there is no change in behavior.
2022-03-29 17:16:28 -07:00
Becca Royal-Gordon
4bd532ab9a Don't import string macros with invalid UTF-8
Swift string literals are only permitted to contain well-formed UTF-8, but C does not share this restriction, and ClangImporter wasn't checking for that before it created `StringLiteralExpr`s for imported macros; this could cause crashes when importing a header. This commit makes us drop these macros instead.

Although invalid UTF-8 always *did* cause a segfault in my testing, I'm not convinced that there isn't a way to cause a miscompile with a bug like this. If we somehow did generate code that fed ill-formed UTF-8 to the builtin literal init for Swift.String, the resulting string could cause undefined behavior at runtime. So I have additionally added a defensive assertion to StringLiteralInst that any UTF-8 string represented in SIL is well-formed. Hopefully that will catch any non-crashing compiler bugs like this one.

Fixes rdar://67840900.
2022-01-26 20:57:13 -08:00
Nuri Amari
130f2de7fd Improve ClangImporter failure diagnostics
This patch introduces new diagnostics to the ClangImporter to help
explain why certain C, Objective-C or C++ declarations fail to import
into Swift. This patch includes new diagnostics for the following entities:

- C functions
- C struct fields
- Macros
- Objective-C properties
- Objective-C methods

In particular, notes are attached to indicate when any of the above
entities fail to import as a result of refering an incomplete (only
forward declared) type.

The new diangostics are hidden behind two new flags, -enable-experimental-clang-importer-diagnostics
and -enable-experimental-eager-clang-module-diagnostics. The first flag emits diagnostics lazily,
while the second eagerly imports all declarations visible from loaded Clang modules. The first
flag is intended for day to day swiftc use, the second for module linting or debugging the importer.
2022-01-02 12:43:59 -05:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04:00
Minhyuk Kim
e924cf6104 Replace usages of StringRef.find(Key) != StringRef::npos to StringRef.contains(Key) 2021-02-04 00:42:04 +09:00
zoecarver
e639caeeea [cxx-interop] Bail on redefined macros.
This is a stop-gap fix to prevent an infinite loop. Refs SR-13828.
2020-11-11 11:08:40 -08:00
Slava Pestov
38477ade9c ClangImporter: Replace some calls to getDeclaredType() with getDeclaredInterfaceType() 2020-07-31 13:39:02 -04:00
Slava Pestov
95843e372c ClangImporter: Remove ConstantConvertKind::{Coerce,Downcast} 2019-05-23 10:40:34 -04:00
Slava Pestov
911d201d51 ClangImporter: Remove RegisteredExternalDecls and finishPendingActions() logic 2018-04-02 23:17:58 -07:00
Jordan Rose
413e7db918 [ClangImporter] Handle diagnostics about cast types in macros
The importer handles these by first trying to look up the type by name
using Clang's Sema, but that lookup can cause diagnostics to be
emitted (usually availability diagnostics). We could try to figure out
how to propagate that to the macro when we import it, but for now just
drop the macro instead if there are any diagnostics emitted when
looking up the type.

This will be a small source compatibility break if anyone was using a
macro defined in terms of a type that's deprecated or that has partial
availability; the macro will now silently not be imported instead of
producing an unsilenceable warning.

rdar://problem/36528212
2018-01-16 13:44:22 -08:00
Mark Lacey
dea38a7710 IUO: Rename some importer functions.
Minor update to improve naming.
2018-01-05 16:52:50 -08:00
Mark Lacey
4ca3e20651 IUO: Update the ClangImporter to surface whether decls are implicitly unwrapped.
Update several functions to return a Type/bool pair with the bool
representing whether the type is one that should be implicitly
unwrapped. This bool is surfaced up to the decl importing functions,
allowing them to set the appropriate decl attribute so that the
expression type checker will consider selecting the underlying type of
the optional involved during solving if the expression doesn't type
check with the optional type.

When importing Decls, use the IUO information to set the
ImplicitlyUnwrappedOptionalAttr attribute when appropriate.

We're still generating IUO types at the moment, so this change doesn't
really have much of an affect other than the creation of those
attributes.
2018-01-04 18:23:42 -08:00
Jordan Rose
5edbefcc69 [ClangImporter] Break circularity when importing macros (#13099)
Rather than being smart about this, just record an import failure when
we start importing a particular macro and update it at the end. Also
add a PrettyStackTrace to make this a little easier to track down in
the future.

The old logic for importing macros that just aliased other macros
managed to handle this in a clever way, but that was never tested for
the newer logic that evaluates expressions (fa834e2f80). Macro
importing in general probably deserves some cleanup, but meanwhile we
should make sure not to crash!

rdar://problem/34986930
2017-12-01 11:42:49 -08:00
Jordan Rose
3717fe600c [ClangImporter] Fix use-after-free in macro importing (#12316)
This has been showing up as nondeterministic failures on our Linux
bots in the clang_builtins.swift test, because that test used to
trigger typo correction! Which pulled in macros, which happened to
include some redefinitions, which resulted in this.

rdar://problem/34266952
2017-10-06 18:20:40 -07:00
Jordan Rose
7efdfb4167 [ClangImporter] Fix macros defined in terms of other macros.
...which didn't do the right thing in the presence of ModuleMacro,
depending on the order the macros were referenced. Already covered by
test/ClangImporter/macros.swift, but it actually seems to improve the
behavior of some of the SourceKit tests as well.

Continuing rdar://problem/32199805, which is just "get macros working
with clang::ModuleMacro".
2017-07-26 15:42:31 -07:00
swift-ci
e98182387b Merge remote-tracking branch 'origin/master' into master-next 2017-07-11 12:23:35 -07:00
John McCall
0e89efa1c8 Bridge types during import only if we are in a fully-bridgeable context.
Somehow the logic had slipped so that we were basing this decision purely
on the ImportTypeKind and not on whether the broader context is bridgeable.
This was allowing us to use bridged types when e.g. importing the results
and parameters of C function pointer types, which is really bad.

Also, when importing a reference to a typedef of block type, do not use
the typedef in a non-bridgeable context.  We import typedefs of block type
as fully-bridged types, but this means that it is invalid to import a type
using the typedef in a context where the original C type must be used.
Similarly, make sure we use a properly-imported underlying type of the
typedef when the typedef itself is unavailable.

Also, extend the special behavior of block typedefs to abstract-function
typedefs, which seems to be consistent with the expected behavior of the
tests.

Finally, I changed importType to take a new Bridgeability enum instead of
a raw canFullyBridgeTypes bool.  At the time, I was doing that because I
was going to make it tri-valued; that turned out to be unnecessary, but I
think it's an improvement anyway.
2017-07-09 13:53:19 -04:00
Jordan Rose
c3d6be64ab WIP Update to use clang::ModuleMacro instead of clang::MacroInfo.
Untested and still missing a few pieces.
2017-06-23 16:04:24 -07:00
Jordan Rose
5de3567364 [ClangImporter] Honor the 'DC' parameter for importStringLiteral.
We don't have any way to import a macro into a different DeclContext
anyway, but even then this saves a bit of unnecessary work.

Groundwork for rdar://problem/32199805, which is that Clang has
removed a bunch of facilities for going from a SourceLocation or
MacroInfo to a Module in favor of things like clang::ModuleMacro.
2017-06-13 11:45:18 -07:00
practicalswift
5e255e07d7 [gardening] Remove redundant logic 2017-04-11 23:04:55 +02:00
Jordan Rose
1439b90b84 [ClangImporter] Fix use-after-scope bug in macro importing. (#8213)
...by using a null clang::QualType as a placeholder instead of a
'QualType *' that might be null.

The problematic case here was when importing builtin types, which
would use the address of a stack local in the later call to
importNumericLiteral. Rather than fix this case specifically I just
simplified the whole thing---the extra level of indirection isn't
buying us anything.

No functionality change, other than not using memory after its
lifetime has ended. Caught by ASan!

rdar://problem/31117311
2017-03-20 17:13:55 -07:00
Graydon Hoare
49231a35e6 [Clang Importer] Make ClangModuleUnit owned by ClangImporter::Implementation. 2017-02-27 15:05:07 -08:00
SpringsUp
fa834e2f80 [ClangImporter] Teach the importer about more infix operators between
integer constants, and to always look through macro definitions for them.

Also, logical comparisons now return a Boolean.

New operations: +, -, *, /, ^, >>, ==, >, >=, <, <=
2017-01-23 21:02:47 +01:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Jordan Rose
672a30552e [ClangImporter] Add a FIXME to a bit of duplicated code.
Comment change only.
2016-12-21 17:53:25 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00
Michael Ilseman
15f5367409 [Clang Importer] Simplify and move more lookup table APIs 2016-12-01 18:18:12 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Michael Ilseman
e092774a08 [Import Name] Ruin SwiftNameLookupExtension and Impl's friendship
SwiftNameLookupExtension and ClangImporter::Implementation were
friends, but as time goes on they have drifted apart. As part of the
ImportName refactoring, these are being decoupled to facilitate
multiple-name importing, and fight the existing false encapsulation
present in the Impl.

SwiftNameLookupExtension is now spun off into its own entity, and can
evolve to have and use its own de-coupled NameImporter.
2016-09-29 11:10:13 -07:00
Michael Ilseman
f4f4acc30d [ImportName] Static-ize many more methods
Change more methods on the Impl to be static, passing down an
ASTContext if necessary. While this does ugly up the functions
slightly with the extra parameter, it decouples them from the Impl,
which has been a false abstraction when building the lookup
tables. These can all be moved to a more appropriate place in the
future.

NFC
2016-09-28 22:40:56 -07:00
Doug Gregor
8fb4deece8 Merge pull request #4509 from IngmarStein/master
[ClangImporter] import compound macros independent of order
2016-09-19 22:02:19 -07:00
Michael Ilseman
5685ad9039 [ClangImporter] Begin refactoring of ImportName
Refactors out some definitions and types from the
ClangImporter::Implementation into a new component ImportName. Future
work will include more separation and finally some redesigning of name
determination components.
2016-09-09 11:05:59 -07:00
Ingmar Stein
98240ab871 [ClangImporter] import compound macros independent of order
This patch fixes an importer problem which occurred for macros defined
in terms of two other macros which might not have been imported before.
For example, the macro CPU_TYPE_X86_64 (defined as CPU_TYPE_X86 |
CPU_ARCH_ABI64) in Foundation wasn't imported although the importing
logic was implemented.

importMacro is now called for each of the constituents before checking
the constant value.
2016-09-03 16:43:11 +02:00
Ingmar Stein
28c141ff63 [ClangImporter] restrict import of macros with typedef'ed casts (#3676)
Import only casts with builtin canonical types to make sure they can be
typechecked.
2016-07-22 17:21:12 -07:00
IngmarStein
48079e7f25 [ClangImporter] fix crash when importing macros with bitwise operators
Fix an assertion which is triggered when the operands of a bitwise operator have different signedness.
This is done by promoting the operands to the largest bit width (taking sign/zero extension into account) and ignoring the signedness for the operation itself.
2016-07-21 13:44:22 +02:00
IngmarStein
e5cd80e21f [ClangImporter] import macros with type casts for some builtin types
This builds on #2538 by adding support for builtin types in addition to typedefs.
2016-07-05 15:33:40 +02:00