[SUA][Runtime] Define `swift_coroFrameAlloc` function that allocates typed memory
Define `swift_coroFrameAlloc` that allocates typed memory if SWIFT_STDLIB_HAS_MALLOC_TYPE is defined.
This function will be used by IRGen to emit typed memory allocations for property accessors.
rdar://141235539
In embedded mode, we mustn't have references to the C++ library, because
some embedded platforms don't include the C++ library.
Additionally, it's good to avoid use of global operator new and operator
delete, because they can be globally overridden and this has bitten us
in the past.
rdar://137286187
clang-15 requires `extern "C"` to be the first attribute and does not
allow mixing GNU attributes and standard attributes. Temporarily split
and re-order attributes to prevent compilation errors. Avoid updating
the public stdlib here (`Visibility.h`) and instead add the definitions
to `Config.h`, which all impacted headers and up including.
This should be removed once Swift uses at least stable/20221013, which
has https://reviews.llvm.org/D137979 and would thus allow us to just
move `SWIFT_RUNTIME_EXPORT` to be the first attribute.
Resolves https://github.com/apple/swift/issues/61468.
This is required to a clang change. Attribute need to be in a certain order when building with a newer clang.
This fix might be replaced by something better, e.g. https://github.com/apple/swift/pull/61476
This replaces a number of `#include`-s like this:
```
#include "../../../stdlib/public/SwiftShims/Visibility.h"
```
with this:
```
#include "swift/shims/Visibility.h"
```
This is needed to allow SwiftCompilerSources to use C++ headers which include SwiftShims headers. Currently trying to do that results in errors:
```
swift/swift/include/swift/Demangling/../../../stdlib/public/SwiftShims/module.modulemap:1:8: error: redefinition of module 'SwiftShims'
module SwiftShims {
^
Builds.noindex/swift/swift/bootstrapping0/lib/swift/shims/module.modulemap:1:8: note: previously defined here
module SwiftShims {
^
```
This happens because the headers in both the source dir and the build dir refer to SwiftShims headers by relative path, and both the source root and the build root contain SwiftShims headers (which are equivalent, but since they are located in different dirs, Clang treats them as different modules).
Not all targets have a 16-byte type alignment guarantee. For the types
which are not naturally aligned, provide a type specific `operator new`
overload to ensure that we are properly aligning the type on allocation
as we run the risk of under-aligned allocations otherwise.
This should no longer be needed with C++17 and newer which do a two
phase `operator new` lookup preferring
`operator new(std::size, std::align_val_t)` if needed. The base type
would be fully pre-processed away. The empty base class optimization
should help ensure that we do not pay any extra size costs for the
alignment fixes.
As we are a C++14 codebase, we must locally implement some of the
standard type_traits utilities, namely `void_t`. We take the minimal
definition here, assuming that the compiler is up-to-date with C++14 DR
reports which fixed an issue in SFINAE. We use the SFINAE for detecting
the presence of the `operator new` overload to guide the over-alignment,
which is inherited through the new `swift::overaligned_type<>` base
type.
Annotate the known classes which request explicit alignment which is
non-pointer alignment. This list was identified by
`git grep ' alignas(.*) '`.
Huge allocation leaks are detected correctly.
Tiny allocation leaks are problematic, both false positive and false negative.
For example:
leaks Report Version: 2.0
Process 73345: 4980 nodes malloced for 1677 KB
Process 73345: 1 leak for 1048576 total leaked bytes.
Leak: 0x10aed0000 size=1048576 zone: SwiftZone_0x10adc35d8
Swift SVN r18007