From 24db8b8bc35a0ce43b03d570fc6a14af3d88dcd1 Mon Sep 17 00:00:00 2001 From: Erik Eckstein Date: Fri, 28 Oct 2022 17:16:51 +0200 Subject: [PATCH] Fix wrong attribute ordering in the runtime again This is required because of a change in clang 15, where attributes need to come after `extern "C"`: https://reviews.llvm.org/D126061 https://github.com/llvm/llvm-project/issues/56077 Fixes #61468 --- include/swift/Runtime/Heap.h | 2 +- include/swift/Runtime/HeapObject.h | 4 ++-- include/swift/Runtime/Metadata.h | 4 ++-- stdlib/public/SwiftShims/swift/shims/Visibility.h | 3 +++ 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/swift/Runtime/Heap.h b/include/swift/Runtime/Heap.h index 4b7f50fb0899a..c9c6cbff10a77 100644 --- a/include/swift/Runtime/Heap.h +++ b/include/swift/Runtime/Heap.h @@ -29,7 +29,7 @@ namespace swift { // Never returns nil. The returned memory is uninitialized. // // An "alignment mask" is just the alignment (a power of 2) minus 1. -SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT +SWIFT_EXTERN_C SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT_ATTRIBUTE void *swift_slowAlloc(size_t bytes, size_t alignMask); // If the caller cannot promise to zero the object during destruction, diff --git a/include/swift/Runtime/HeapObject.h b/include/swift/Runtime/HeapObject.h index c0de2f46ff2de..62c178285d2a9 100644 --- a/include/swift/Runtime/HeapObject.h +++ b/include/swift/Runtime/HeapObject.h @@ -61,7 +61,7 @@ struct OpaqueValue; /// /// POSSIBILITIES: The argument order is fair game. It may be useful /// to have a variant which guarantees zero-initialized memory. -SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT +SWIFT_EXTERN_C SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT_ATTRIBUTE HeapObject *swift_allocObject(HeapMetadata const *metadata, size_t requiredSize, size_t requiredAlignmentMask); @@ -117,7 +117,7 @@ BoxPair swift_makeBoxUnique(OpaqueValue *buffer, Metadata const *type, size_t alignMask); /// Returns the address of a heap object representing all empty box types. -SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT +SWIFT_EXTERN_C SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT_ATTRIBUTE HeapObject* swift_allocEmptyBox(); /// Atomically increments the retain count of an object. diff --git a/include/swift/Runtime/Metadata.h b/include/swift/Runtime/Metadata.h index 9114d7462ccc4..edc55608e454a 100644 --- a/include/swift/Runtime/Metadata.h +++ b/include/swift/Runtime/Metadata.h @@ -313,7 +313,7 @@ swift_getGenericMetadata(MetadataRequest request, /// - installing new v-table entries and overrides; and /// - registering the class with the runtime under ObjC interop. /// Most of this work can be achieved by calling swift_initClassMetadata. -SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT +SWIFT_EXTERN_C SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT_ATTRIBUTE ClassMetadata * swift_allocateGenericClassMetadata(const ClassDescriptor *description, const void *arguments, @@ -322,7 +322,7 @@ swift_allocateGenericClassMetadata(const ClassDescriptor *description, /// Allocate a generic value metadata object. This is intended to be /// called by the metadata instantiation function of a generic struct or /// enum. -SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT +SWIFT_EXTERN_C SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT_ATTRIBUTE ValueMetadata * swift_allocateGenericValueMetadata(const ValueTypeDescriptor *description, const void *arguments, diff --git a/stdlib/public/SwiftShims/swift/shims/Visibility.h b/stdlib/public/SwiftShims/swift/shims/Visibility.h index ce7a478a28174..a34e7cbc1041c 100644 --- a/stdlib/public/SwiftShims/swift/shims/Visibility.h +++ b/stdlib/public/SwiftShims/swift/shims/Visibility.h @@ -217,10 +217,13 @@ // TODO: use this in shims headers in overlays. #if defined(__cplusplus) #define SWIFT_EXPORT_FROM(LIBRARY) extern "C" SWIFT_EXPORT_FROM_ATTRIBUTE(LIBRARY) +#define SWIFT_EXTERN_C extern "C" #else #define SWIFT_EXPORT_FROM(LIBRARY) SWIFT_EXPORT_FROM_ATTRIBUTE(LIBRARY) +#define SWIFT_EXTERN_C #endif #define SWIFT_RUNTIME_EXPORT SWIFT_EXPORT_FROM(swiftCore) +#define SWIFT_RUNTIME_EXPORT_ATTRIBUTE SWIFT_EXPORT_FROM_ATTRIBUTE(swiftCore) #if __cplusplus > 201402l && __has_cpp_attribute(fallthrough) #define SWIFT_FALLTHROUGH [[fallthrough]]