Commit Graph

22 Commits

Author SHA1 Message Date
Alexis Laferrière
d5b31328cd PrintAsObjc Test: Test compatibility headers for C 2025-04-18 11:43:27 -07:00
Becca Royal-Gordon
da07ff577c [PrintAsClang] Warn about unstable decl order
PrintAsClang is supposed to emit declarations in the same order regardless of the compiler’s internal state, but we have repeatedly found that our current criteria are inadequate, resulting in non-functionality-affecting changes to generated header content. Add a diagnostic that’s emitted when this happens soliciting a bug report.

Since there *should* be no cases where the compiler fails to order declarations, this diagnostic is never actually emitted. Instead, we test this change by enabling `-verify` on nearly all PrintAsClang tests to make sure they are unaffected.

This did demonstrate a missing criterion that only mattered in C++ mode: extensions that varied only in their generic signature were not sorted stably. Add a sort criterion for this.
2025-02-14 21:41:36 -08:00
Daniel Rodríguez Troitiño
00e866ae53 [cxx-interop] noexcept specifier before function attributes (#74780)
In #74516 the `SWIFT_NOEXCEPT` specifier is added to the imported Swift
functions in C++ mode, but it is added after the function attributes. It seems
that the tests only do `-fsyntax-only`, which seems not to catch an error like
"expected function body after function declarator" when the header is
used without that flag.

Flip the attributes and the specifier around in the printer, and flip
them in all the tests.

The tests were using `%check-in-clang`, but it only checks importing as
an objective-c-header. Add a parallel `%check-in-clang-cxx` to test also
in C++. It uses C++17 because of some details in the imported headers and
disables a warning about variadic macros that was promoted to an error
and was blocking passing the tests. The clang-importer-sdk gets the
minimal set of files to compile the two modified tests as C++. The files
are mostly empty, except `cstddef` that imports the equivalent C header.
Some modifications were needed in `ctypes.h` because the header was
using features only available in C and not C++.
2024-06-27 22:49:03 -07:00
Gabor Horvath
5bb9ccf149 [cxx-interop] Fix exporing cdecl Swift functions to Obj-C++
We export cdecl function declarations twice: for Objective-C and for
C++. When the code is compiled in Objective-C++ both of the declarations
are visible to the compiler. The generated header did not compile,
because only one of the declarations were noexcept. There are multiple
possible ways to fix this issue, one of them would make only C++
declarations visible in Objective-C++ mode. However, for this particular
problem I decided to also make the Objective-C functions SWIFT_NOEXCEPT.
This approach resolves the inconsistency that broke the code when
compiled in Objective-C++ mode. Moreover, Swift guarantees that those
cdecl declarations cannot raise errors, so in case we only generate the
C declarations and consume them from C++ or Objective-C++, those are the
correct declarations.

rdar://129550313
2024-06-18 16:40:34 +01:00
Anton Korobeynikov
581b13fe31 Ignore "noescape" bit for all @convention(c) function pointers 2022-04-20 10:34:45 +02:00
Saleem Abdulrasool
36c951d31e Revert "[DebugInfo] Ignore noescape bit for all @convention(c) pointers" 2022-04-19 18:09:23 -07:00
Anton Korobeynikov
07396c5de6 Ignore "noescape" bit for all @convention(c) function pointers 2022-04-18 22:43:57 +02:00
Mark Rowe
7a64bf7aa7 Prefix @_cdecl functions with extern "C" in -Swift.h headers
This ensures that the function uses the appropriate mangling if the header is imported and the function is used from Objective-C++ code.
2021-07-28 15:59:52 -07:00
Mani Ramezan
9df5adb150 Move mock Foundation framework into clang shared folder 2018-07-11 02:32:59 -04:00
Mark Lacey
5b7ebd7c4f IUO: Updates to PrintAsObjC to use the decl attribute for IUO.
Use the attribute to update the OptionalTypeKind used for various
decls that we print.

I added test cases to make sure we were exercising all the modified
code paths.
2018-01-11 23:48:32 -08:00
Dmitri Gribenko
984210aa53 tests: replace '// RUN: rm -rf' '// RUN: mkdir' pairs with '%empty-directory(...)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
Rintaro Ishizaki
f02c155864 [PrintAsObjC] Add return type related attributes to '_cdecl' global functions
Additionally, Print '(void)' instead '()' for functions that takes no arguments.
2017-01-30 13:56:19 +09:00
Daniel Martín
d510793566 Fix SR-2860 2017-01-16 09:39:36 +01:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Dmitri Gribenko
55864d10cb Tests: use 'mkdir -p' 2016-09-02 21:36:45 -07:00
Jacob Bandes-Storch
89d0d62bd6 [PrintAsObjC] print __attribute__((noescape)) in Obj-C headers (#4438)
https://bugs.swift.org/browse/SR-2406
2016-08-31 09:27:59 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Chris Lattner
8c1c0bed8c update the last of the testsuite to have parens around function type parameters. 2016-05-06 21:07:08 -07:00
David Farler
4d8b33e5ba Markup: Move Doxygen converter into a proper MarkupASTNode visitor
Enclose the entire doc comment in /** */ to ensure that newlines
don't cause comments to leak out and get parsed as C.

rdar://problem/24923076
2016-05-03 16:44:31 -07:00
Saleem Abdulrasool
89d37bc694 test: ignore unused options in some tests
These tests explicitly disable the use of modules.  However, the lit
configuration is such that the module cache path will be passed unconditionally
to the clang invocation.  Squelch the unused option warning (error).
2016-04-05 10:00:37 -07:00
Drew Crawford
aa5cf2b842 [Serialization] Don't serialize non-public documentation
Let's say I am a good citizen and document my private symbols:

    /** My TOP SECRET DOCUMENTATION */
    private class Foo {
    }

When I go to distribute the compiled binary, I find out my private
documentation is distributed as well:

    $ swiftc test.swift -emit-module -module-name "test"
    $ strings test.swiftdoc
    My TOP SECRET DOCUMENTATION
    /** My TOP SECRET DOCUMENTATION */

If a client can't use a symbol (e.g. it's private [or internal and not
-enable-testing]) don't emit the documentation for a symbol in the
swiftdoc.

Fixes: SR-762, rdar://21453624

The test coverage implements this truth table:

| visibility | -enable-testing | documentation? |
|------------|-----------------|----------------|
| private    | no              |              |
| internal   | no              |              |
| public     | no              |              |
| private    | yes             |              |
| internal   | yes             |              |
| public     | yes             |              |

Modified the existing comments test coverage to expect non-public
documentation not to be emitted.

Don't rely on existing comment structure

Refuse to emit comments if the decl cannot actually have one.  To
accomplish this, we move `canHaveComment` into the Decl instance.  It
must also be marked `const`, since one of its existing usages operates
on a const pointer.

Perform fewer checks when serializing the standard library.
2016-03-17 17:46:23 -05:00
Joe Groff
013aad13d4 Initial implementation of a @_cdecl attribute to export top-level functions to C.
There's an immediate need for this in the core libs, and we have most of the necessary pieces on hand to make it easy to implement. This is an unpolished initial implementation, with the following limitations, among others:

- It doesn't support bridging error conventions,
- It relies on ObjC interop,
- It doesn't check for symbol name collisions,
- It has an underscored name with required symbol name `@cdecl("symbol_name")`, awaiting official bikeshed painting.
2016-03-10 13:27:39 -08:00