Skip to content

Commit bf3eec4

Browse files
authored
Merge pull request #58712 from grynspan/jgrynspan/58711-add-nodiscard-annotation
2 parents 61e762d + 9644c73 commit bf3eec4

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

include/swift/Runtime/Heap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ 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_RUNTIME_EXPORT
32+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
3333
void *swift_slowAlloc(size_t bytes, size_t alignMask);
3434

3535
// If the caller cannot promise to zero the object during destruction,
@@ -53,7 +53,7 @@ void swift_slowDealloc(void *ptr, size_t bytes, size_t alignMask);
5353
/// This function is capable of returning well-aligned memory even on platforms
5454
/// that do not implement the C++17 "over-aligned new" feature.
5555
template <typename T, typename... Args>
56-
SWIFT_RETURNS_NONNULL
56+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD
5757
static inline T *swift_cxx_newObject(Args &&... args) {
5858
auto result = reinterpret_cast<T *>(swift_slowAlloc(sizeof(T),
5959
alignof(T) - 1));

include/swift/Runtime/HeapObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ 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_RUNTIME_EXPORT
64+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
6565
HeapObject *swift_allocObject(HeapMetadata const *metadata,
6666
size_t requiredSize,
6767
size_t requiredAlignmentMask);
@@ -117,7 +117,7 @@ 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_RUNTIME_EXPORT
120+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
121121
HeapObject* swift_allocEmptyBox();
122122

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

include/swift/Runtime/Metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ swift_getGenericMetadata(MetadataRequest request,
307307
/// - installing new v-table entries and overrides; and
308308
/// - registering the class with the runtime under ObjC interop.
309309
/// Most of this work can be achieved by calling swift_initClassMetadata.
310-
SWIFT_RETURNS_NONNULL SWIFT_RUNTIME_EXPORT
310+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
311311
ClassMetadata *
312312
swift_allocateGenericClassMetadata(const ClassDescriptor *description,
313313
const void *arguments,
@@ -316,7 +316,7 @@ swift_allocateGenericClassMetadata(const ClassDescriptor *description,
316316
/// Allocate a generic value metadata object. This is intended to be
317317
/// called by the metadata instantiation function of a generic struct or
318318
/// enum.
319-
SWIFT_RETURNS_NONNULL SWIFT_RUNTIME_EXPORT
319+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
320320
ValueMetadata *
321321
swift_allocateGenericValueMetadata(const ValueTypeDescriptor *description,
322322
const void *arguments,

stdlib/public/runtime/HeapObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static inline bool isValidPointerForNativeRetain(const void *p) {
9393
// not to emit a bunch of ptrauth instructions just to perform the comparison.
9494
// We only want to authenticate the function pointer if we actually call it. We
9595
// can revert to a straight comparison once rdar://problem/55267009 is fixed.
96-
SWIFT_RETURNS_NONNULL
96+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD
9797
static HeapObject *_swift_allocObject_(HeapMetadata const *metadata,
9898
size_t requiredSize,
9999
size_t requiredAlignmentMask)

stdlib/public/runtime/MetadataCache.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class MetadataAllocator : public llvm::AllocatorBase<MetadataAllocator> {
4040

4141
void Reset() {}
4242

43-
SWIFT_RETURNS_NONNULL void *Allocate(size_t size, size_t alignment);
43+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD
44+
void *Allocate(size_t size, size_t alignment);
4445
using AllocatorBase<MetadataAllocator>::Allocate;
4546

4647
void Deallocate(const void *Ptr, size_t size, size_t Alignment);
@@ -60,7 +61,8 @@ class MetadataAllocator : public llvm::AllocatorBase<MetadataAllocator> {
6061
class MetadataAllocator {
6162
public:
6263
MetadataAllocator(uint16_t tag) {}
63-
SWIFT_RETURNS_NONNULL void *Allocate(size_t size, size_t alignment) {
64+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD
65+
void *Allocate(size_t size, size_t alignment) {
6466
if (alignment < sizeof(void*)) alignment = sizeof(void*);
6567
void *ptr = nullptr;
6668
if (SWIFT_UNLIKELY(posix_memalign(&ptr, alignment, size) != 0 || !ptr)) {

stdlib/public/runtime/Private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ class TypeInfo {
516516
}
517517
}
518518

519-
SWIFT_RETURNS_NONNULL
519+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD
520520
void *allocateMetadata(size_t size, size_t align);
521521

522522
/// Gather the set of generic arguments that would be written in the

0 commit comments

Comments
 (0)