Skip to content

Commit 7ed3058

Browse files
authored
Merge pull request #31610 from compnerd/abused-macros
runtime: add and switch to `SWIFT_USED` (NFC)
2 parents 3abb0bd + b74f426 commit 7ed3058

File tree

8 files changed

+23
-31
lines changed

8 files changed

+23
-31
lines changed

stdlib/public/SwiftShims/HeapObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct HeapObject {
6565
{ }
6666

6767
#ifndef NDEBUG
68-
void dump() const LLVM_ATTRIBUTE_USED;
68+
void dump() const SWIFT_USED;
6969
#endif
7070

7171
#endif // __swift__

stdlib/public/SwiftShims/RefCount.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ namespace swift {
182182
}
183183

184184
// FIXME: HACK: copied from HeapObject.cpp
185-
extern "C" SWIFT_LIBRARY_VISIBILITY SWIFT_NOINLINE LLVM_ATTRIBUTE_USED void
185+
extern "C" SWIFT_LIBRARY_VISIBILITY SWIFT_NOINLINE SWIFT_USED void
186186
_swift_release_dealloc(swift::HeapObject *object);
187187

188188
namespace swift {

stdlib/public/SwiftShims/Visibility.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
#define SWIFT_NOINLINE
7373
#endif
7474

75+
#if __has_attribute(used)
76+
#define SWIFT_USED __attribute__((__used__))
77+
#else
78+
#define SWIFT_USED
79+
#endif
80+
7581
#if __has_attribute(unavailable)
7682
#define SWIFT_ATTRIBUTE_UNAVAILABLE __attribute__((__unavailable__))
7783
#else

stdlib/public/runtime/ExistentialContainer.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ void OpaqueExistentialContainer::deinit() {
5656

5757
// *NOTE* This routine performs unused memory reads on purpose to try to catch
5858
// use-after-frees in conjunction with ASAN or Guard Malloc.
59-
template <>
60-
LLVM_ATTRIBUTE_USED
61-
void OpaqueExistentialContainer::verify() const {
59+
template <> SWIFT_USED void OpaqueExistentialContainer::verify() const {
6260
// We do not actually care about value. We just want to see if the
6361
// memory is valid or not. So convert to a uint8_t and try to
6462
// memcpy into firstByte. We use volatile to just ensure that this
@@ -70,9 +68,7 @@ void OpaqueExistentialContainer::verify() const {
7068
}
7169

7270
/// Dump information about this specific container and its contents.
73-
template <>
74-
LLVM_ATTRIBUTE_USED
75-
void OpaqueExistentialContainer::dump() const {
71+
template <> SWIFT_USED void OpaqueExistentialContainer::dump() const {
7672
// Quickly verify to make sure we are well formed.
7773
verify();
7874

stdlib/public/runtime/HeapObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ HeapObject *swift::swift_allocEmptyBox() {
327327
}
328328

329329
// Forward-declare this, but define it after swift_release.
330-
extern "C" SWIFT_LIBRARY_VISIBILITY SWIFT_NOINLINE LLVM_ATTRIBUTE_USED void
330+
extern "C" SWIFT_LIBRARY_VISIBILITY SWIFT_NOINLINE SWIFT_USED void
331331
_swift_release_dealloc(HeapObject *object);
332332

333333
static HeapObject *_swift_retain_(HeapObject *object) {

stdlib/public/runtime/Leaks.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ struct HeapObject;
3131
}
3232

3333
SWIFT_CC(swift)
34-
SWIFT_RUNTIME_EXPORT SWIFT_NOINLINE LLVM_ATTRIBUTE_USED
35-
void _swift_leaks_startTrackingObjects(const char *);
34+
SWIFT_RUNTIME_EXPORT SWIFT_NOINLINE SWIFT_USED void
35+
_swift_leaks_startTrackingObjects(const char *);
3636

3737
SWIFT_CC(swift)
38-
SWIFT_RUNTIME_EXPORT SWIFT_NOINLINE LLVM_ATTRIBUTE_USED
39-
int _swift_leaks_stopTrackingObjects(const char *);
38+
SWIFT_RUNTIME_EXPORT SWIFT_NOINLINE SWIFT_USED int
39+
_swift_leaks_stopTrackingObjects(const char *);
4040

41-
SWIFT_RUNTIME_EXPORT SWIFT_NOINLINE LLVM_ATTRIBUTE_USED void
41+
SWIFT_RUNTIME_EXPORT SWIFT_NOINLINE SWIFT_USED void
4242
_swift_leaks_startTrackingObject(swift::HeapObject *);
4343

44-
SWIFT_RUNTIME_EXPORT SWIFT_NOINLINE LLVM_ATTRIBUTE_USED void
44+
SWIFT_RUNTIME_EXPORT SWIFT_NOINLINE SWIFT_USED void
4545
_swift_leaks_stopTrackingObject(swift::HeapObject *);
4646

4747
#define SWIFT_LEAKS_START_TRACKING_OBJECT(obj) \

stdlib/public/runtime/Metadata.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4142,9 +4142,7 @@ StringRef swift::getStringForMetadataKind(MetadataKind kind) {
41424142
/***************************************************************************/
41434143

41444144
#ifndef NDEBUG
4145-
template <>
4146-
LLVM_ATTRIBUTE_USED
4147-
void Metadata::dump() const {
4145+
template <> SWIFT_USED void Metadata::dump() const {
41484146
printf("TargetMetadata.\n");
41494147
printf("Kind: %s.\n", getStringForMetadataKind(getKind()).data());
41504148
printf("Value Witnesses: %p.\n", getValueWitnesses());
@@ -4197,9 +4195,7 @@ void Metadata::dump() const {
41974195
#endif
41984196
}
41994197

4200-
template <>
4201-
LLVM_ATTRIBUTE_USED
4202-
void ContextDescriptor::dump() const {
4198+
template <> SWIFT_USED void ContextDescriptor::dump() const {
42034199
printf("TargetTypeContextDescriptor.\n");
42044200
printf("Flags: 0x%x.\n", this->Flags.getIntValue());
42054201
printf("Parent: %p.\n", this->Parent.get());
@@ -4211,9 +4207,7 @@ void ContextDescriptor::dump() const {
42114207
}
42124208
}
42134209

4214-
template<>
4215-
LLVM_ATTRIBUTE_USED
4216-
void EnumDescriptor::dump() const {
4210+
template <> SWIFT_USED void EnumDescriptor::dump() const {
42174211
printf("TargetEnumDescriptor.\n");
42184212
printf("Flags: 0x%x.\n", this->Flags.getIntValue());
42194213
printf("Parent: %p.\n", this->Parent.get());

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
using namespace swift;
3232

3333
#ifndef NDEBUG
34-
template <>
35-
LLVM_ATTRIBUTE_USED
36-
void ProtocolDescriptor::dump() const {
34+
template <> SWIFT_USED void ProtocolDescriptor::dump() const {
3735
printf("TargetProtocolDescriptor.\n"
3836
"Name: \"%s\".\n",
3937
Name.get());
@@ -95,9 +93,7 @@ template<> void ProtocolConformanceDescriptor::dump() const {
9593
#endif
9694

9795
#ifndef NDEBUG
98-
template<>
99-
LLVM_ATTRIBUTE_USED
100-
void ProtocolConformanceDescriptor::verify() const {
96+
template <> SWIFT_USED void ProtocolConformanceDescriptor::verify() const {
10197
auto typeKind = unsigned(getTypeKind());
10298
assert(((unsigned(TypeReferenceKind::First_Kind) <= typeKind) &&
10399
(unsigned(TypeReferenceKind::Last_Kind) >= typeKind)) &&
@@ -302,7 +298,7 @@ struct ConformanceState {
302298
}
303299

304300
#ifndef NDEBUG
305-
void verify() const LLVM_ATTRIBUTE_USED;
301+
void verify() const SWIFT_USED;
306302
#endif
307303
};
308304

0 commit comments

Comments
 (0)