Commit Graph

78 Commits

Author SHA1 Message Date
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
practicalswift
dd93d551df [gardening] Fix recently introduced typos 2016-07-01 19:28:34 +02:00
IngmarStein
31ab594b16 [ClangImporter] check bit width for bitwise operators 2016-06-29 23:01:30 +02:00
IngmarStein
f7a48a8733 [ClangImporter] Parse the type cast before pattern matching when importing macros
Setup the cast type early so that applies to all cases (as suggested by @DougGregor).
2016-06-29 23:01:30 +02:00
IngmarStein
b627123fc8 [ClangImporter] import macros of the form FLAG1 || FLAG2 and FLAG1 && FLAG2
Add another pattern to import
2016-06-29 23:01:30 +02:00
Ingmar Stein
11f1d96d23 Import macros of the form "FLAG1 | FLAG2" and "FLAG1 & FLAG2"
This commit adds a map to ClangImporter::Implementation to remember macros that were imported as constants in order to reuse the calculated values.
2016-06-29 23:01:30 +02:00
Ingmar Stein
4f800f8a21 [ClangImporter] Import preprocessor constants with a cast
Addresses SR-1509 by adding a heuristic to import numeric literals with a
type cast. Two new cases have been added for macros with 4 or 5 tokens
to cover cases with or without sign tokens.
2016-06-29 23:01:30 +02:00
Andrew Trick
ff02652108 Move enums into AttrKind.h.
This reorganization allows adding attributes that refer to types.
I need this for a @_specialize attribute with a type list.

PrintOptions.h and other headers depend on these enums. But Attr.h
defines a lot of classes that almost never need to be included.
2016-02-26 21:10:22 -08:00
Doug Gregor
8e000fb738 [Clang importer] Factor mapping of macro names into a single location. NFC 2016-02-03 16:11:59 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Doug Gregor
4c6d972691 Clang importer: collapse redefined macros.
In C, macros can be redefined so long as the redefinitions are
tokenwise equivalent. Provide the Clang importer with the same ability by
determining when tokenwise equivalent macros would be imported as
different Swift declarations, and collapse them into a single
declaration.
2015-12-21 14:43:46 -08:00
Jordan Rose
0b5428fcd3 Import DarwinBoolean as Bool in fully-bridgeable contexts.
These are contexts where we have enough information to bridge /back/
properly; that is, where we can distinguish CBool, ObjCBool, and
DarwinBoolean. In cases where we can't, we keep the three separate;
only CBool is really the same type as Bool.

This also affects current import behavior for ObjCBool, which was previously
incorrectly conflated with CBool in certain cases.

More rdar://problem/19013551

Swift SVN r30051
2015-07-10 01:11:30 +00:00
Dmitri Hrybenko
89a87c3c65 Revert "[test] Disable/remove tests that rely on iterating over all Clang macros."
...and add one extra check for invalid macro info.

This reinstates the tests that were disabled in my previous commit, now that the
Clang issue has been fixed.

Finishes rdar://problem/21480635.

Patch by Jordan Rose.

Swift SVN r29705
2015-06-25 22:01:44 +00:00
Dmitri Hrybenko
bc371ec1a2 [ClangImporter] Update for changes to how Clang manages macros in modules.
- Macros that aren't visible won't have macro info.
- Making a module visible to Sema doesn't make it visible to the Preprocessor.

Part of rdar://problem/21480635

Patch by Jordan Rose.

Swift SVN r29703
2015-06-25 22:01:42 +00:00
Chris Willmore
6d428b8d52 ClangImporter: Import macros of the form '#define FOO CFSTR("bar")'.
rdar://problem/18668528

Swift SVN r23544
2014-11-22 02:33:27 +00:00
Argyrios Kyrtzidis
a72c0e50c2 [ClangImporter] Expose a couple of functions in ClangImporter.
- getClangSema()
- shouldIgnoreMacro() which returns true if it is expected that a clang macro is ignored.

Swift SVN r23468
2014-11-20 05:08:36 +00:00
Anna Zaks
8cb6d45efb Only remap NSUInteger to Int in system frameworks
Makes NSUInteger come in as Uint from user declarations (and as Int from system modules).
Addresses radar://17473606

Swift SVN r19536
2014-07-03 21:46:47 +00:00
Joe Groff
10fae3e228 Remove -enable-string-pointer-conversion staging flag.
Swift SVN r19524
2014-07-03 18:43:20 +00:00
Joe Groff
c34b4f6a9e Enable string-to-pointer conversions and remove CString.
There is some follow-up work remaining:

- test/stdlib/UnicodeTrie test kills the type checker without manual type annotations. <rdar://problem/17539704>
- test/Sema/availability test raises a type error on 'a: String == nil', which we want, but probably not as a side effect of string-to-pointer conversions. I'll fix this next.

Swift SVN r19477
2014-07-02 19:15:10 +00:00
Joe Groff
e3b8a397a0 Import C string literal macros as ConstUnsafePointer<CChar> when string pointer conversions are enabled.
Swift SVN r19391
2014-07-01 04:48:52 +00:00
Ben Langmuir
133c469e05 Update for clang r211763
pointer, count -> ArrayRef

Swift SVN r19237
2014-06-26 16:28:41 +00:00
Jordan Rose
54c0baa9aa [ClangImporter] Don't recurse infinitely on "#define X X".
<rdar://problem/17182523>

Swift SVN r18772
2014-06-10 01:18:29 +00:00