Skip to content

Commit c738e09

Browse files
allevatoedymtt
authored andcommitted
Move SWIFT_RETURNS_NONNULL and SWIFT_NODISCARD attributes after the function name for exported functions.
More recent versions of Clang (~July 2022) have stricter enforcement of the positioning of attributes; for example, the `nonnull` and `nodiscard` attributes can no longer precede the `extern "C"` specifier and must follow the name of the function (and not the signature of the function) to which they apply. (cherry picked from commit 2963c38)
1 parent de26903 commit c738e09

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

include/swift/Runtime/Heap.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ namespace swift {
2929
// Never returns nil. The returned memory is uninitialized.
3030
//
3131
// An "alignment mask" is just the alignment (a power of 2) minus 1.
32-
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
33-
void *swift_slowAlloc(size_t bytes, size_t alignMask);
32+
SWIFT_RUNTIME_EXPORT
33+
void *swift_slowAlloc SWIFT_RETURNS_NONNULL SWIFT_NODISCARD(size_t bytes,
34+
size_t alignMask);
3435

3536
// If the caller cannot promise to zero the object during destruction,
3637
// then call these corresponding APIs:

include/swift/Runtime/HeapObject.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ struct OpaqueValue;
6161
///
6262
/// POSSIBILITIES: The argument order is fair game. It may be useful
6363
/// to have a variant which guarantees zero-initialized memory.
64-
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
65-
HeapObject *swift_allocObject(HeapMetadata const *metadata,
66-
size_t requiredSize,
67-
size_t requiredAlignmentMask);
64+
SWIFT_RUNTIME_EXPORT
65+
HeapObject *swift_allocObject SWIFT_RETURNS_NONNULL
66+
SWIFT_NODISCARD(HeapMetadata const *metadata, size_t requiredSize,
67+
size_t requiredAlignmentMask);
6868

6969
/// Initializes the object header of a stack allocated object.
7070
///
@@ -117,8 +117,8 @@ BoxPair swift_makeBoxUnique(OpaqueValue *buffer, Metadata const *type,
117117
size_t alignMask);
118118

119119
/// Returns the address of a heap object representing all empty box types.
120-
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
121-
HeapObject* swift_allocEmptyBox();
120+
SWIFT_RUNTIME_EXPORT
121+
HeapObject *swift_allocEmptyBox SWIFT_RETURNS_NONNULL SWIFT_NODISCARD();
122122

123123
/// Atomically increments the retain count of an object.
124124
///

include/swift/Runtime/Metadata.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,19 @@ swift_getGenericMetadata(MetadataRequest request,
313313
/// - installing new v-table entries and overrides; and
314314
/// - registering the class with the runtime under ObjC interop.
315315
/// Most of this work can be achieved by calling swift_initClassMetadata.
316-
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
317-
ClassMetadata *
318-
swift_allocateGenericClassMetadata(const ClassDescriptor *description,
319-
const void *arguments,
320-
const GenericClassMetadataPattern *pattern);
316+
SWIFT_RUNTIME_EXPORT
317+
ClassMetadata *swift_allocateGenericClassMetadata SWIFT_RETURNS_NONNULL
318+
SWIFT_NODISCARD(const ClassDescriptor *description, const void *arguments,
319+
const GenericClassMetadataPattern *pattern);
321320

322321
/// Allocate a generic value metadata object. This is intended to be
323322
/// called by the metadata instantiation function of a generic struct or
324323
/// enum.
325-
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
326-
ValueMetadata *
327-
swift_allocateGenericValueMetadata(const ValueTypeDescriptor *description,
328-
const void *arguments,
329-
const GenericValueMetadataPattern *pattern,
330-
size_t extraDataSize);
324+
SWIFT_RUNTIME_EXPORT
325+
ValueMetadata *swift_allocateGenericValueMetadata SWIFT_RETURNS_NONNULL
326+
SWIFT_NODISCARD(const ValueTypeDescriptor *description, const void *arguments,
327+
const GenericValueMetadataPattern *pattern,
328+
size_t extraDataSize);
331329

332330
/// Check that the given metadata has the right state.
333331
SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)

0 commit comments

Comments
 (0)