Skip to content

Commit a741542

Browse files
committed
runtime: add and switch to SWIFT_FALLTHROUGH (NFC)
This duplicates and switches the uses of `LLVM_FALLTHROUGH` to a local macro for the same annotation.
1 parent 53055fa commit a741542

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

stdlib/public/Reflection/TypeLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ class ExistentialTypeInfoBuilder {
11181118
switch (FD->Kind) {
11191119
case FieldDescriptorKind::Class:
11201120
Refcounting = ReferenceCounting::Native;
1121-
LLVM_FALLTHROUGH;
1121+
SWIFT_FALLTHROUGH;
11221122

11231123
case FieldDescriptorKind::ObjCClass:
11241124
addAnyObject();

stdlib/public/Reflection/TypeRef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ class DemanglingForTypeRef
537537
}
538538

539539
// Otherwise it requires a tuple wrapper.
540-
LLVM_FALLTHROUGH;
540+
SWIFT_FALLTHROUGH;
541541
}
542542

543543
// This covers both none and multiple parameters.

stdlib/public/SwiftShims/Visibility.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#define __has_builtin(builtin) 0
3131
#endif
3232

33+
#if !defined(__has_cpp_attribute)
34+
#define __has_cpp_attribute(attribute) 0
35+
#endif
36+
3337
#if __has_feature(nullability)
3438
// Provide macros to temporarily suppress warning about the use of
3539
// _Nullable and _Nonnull.
@@ -127,6 +131,18 @@
127131
#define SWIFT_RUNTIME_EXPORT SWIFT_EXPORT_ATTRIBUTE
128132
#endif
129133

134+
#if __cplusplus > 201402l && __has_cpp_attribute(fallthrough)
135+
#define SWIFT_FALLTHROUGH [[fallthrough]]
136+
#elif __has_cpp_attribute(gnu::fallthrough)
137+
#define SWIFT_FALLTHROUGH [[gnu::fallthrough]]
138+
#elif __has_cpp_attribute(clang::fallthrough)
139+
#define SWIFT_FALLTHROUGH [[clang::fallthrough]]
140+
#elif __has_attribute(fallthrough)
141+
#define SWIFT_FALLTHROUGH __attribute__((__fallthrough__))
142+
#else
143+
#define SWIFT_FALLTHROUGH
144+
#endif
145+
130146

131147
/// Attributes for runtime-stdlib interfaces.
132148
/// Use these for C implementations that are imported into Swift via SwiftShims

stdlib/public/runtime/Casting.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ static bool _dynamicCastToExistential(OpaqueValue *dest,
896896
maybeDeallocateSource(result);
897897
return result;
898898
}
899-
LLVM_FALLTHROUGH;
899+
SWIFT_FALLTHROUGH;
900900

901901
case MetadataKind::Enum:
902902
case MetadataKind::Optional:
@@ -912,7 +912,7 @@ static bool _dynamicCastToExistential(OpaqueValue *dest,
912912
maybeDeallocateSource(success);
913913
return success;
914914
}
915-
LLVM_FALLTHROUGH;
915+
SWIFT_FALLTHROUGH;
916916

917917
default:
918918
return fallbackForNonClass();
@@ -1129,15 +1129,15 @@ swift_dynamicCastMetatypeImpl(const Metadata *sourceType,
11291129
// Get the actual class object.
11301130
targetType = static_cast<const ObjCClassWrapperMetadata*>(targetType)
11311131
->Class;
1132-
LLVM_FALLTHROUGH;
1132+
SWIFT_FALLTHROUGH;
11331133
case MetadataKind::Class:
11341134
// The source value must also be a class; otherwise the cast fails.
11351135
switch (sourceType->getKind()) {
11361136
case MetadataKind::ObjCClassWrapper:
11371137
// Get the actual class object.
11381138
sourceType = static_cast<const ObjCClassWrapperMetadata*>(sourceType)
11391139
->Class;
1140-
LLVM_FALLTHROUGH;
1140+
SWIFT_FALLTHROUGH;
11411141
case MetadataKind::Class: {
11421142
// Check if the source is a subclass of the target.
11431143
#if SWIFT_OBJC_INTEROP
@@ -1173,7 +1173,7 @@ swift_dynamicCastMetatypeImpl(const Metadata *sourceType,
11731173
// Get the actual class object.
11741174
sourceType = static_cast<const ObjCClassWrapperMetadata*>(sourceType)
11751175
->Class;
1176-
LLVM_FALLTHROUGH;
1176+
SWIFT_FALLTHROUGH;
11771177
case MetadataKind::Class:
11781178
case MetadataKind::ForeignClass:
11791179
// Check if the source is a subclass of the target.
@@ -1216,15 +1216,15 @@ swift_dynamicCastMetatypeUnconditionalImpl(const Metadata *sourceType,
12161216
// Get the actual class object.
12171217
targetType = static_cast<const ObjCClassWrapperMetadata*>(targetType)
12181218
->Class;
1219-
LLVM_FALLTHROUGH;
1219+
SWIFT_FALLTHROUGH;
12201220
case MetadataKind::Class:
12211221
// The source value must also be a class; otherwise the cast fails.
12221222
switch (sourceType->getKind()) {
12231223
case MetadataKind::ObjCClassWrapper:
12241224
// Get the actual class object.
12251225
sourceType = static_cast<const ObjCClassWrapperMetadata*>(sourceType)
12261226
->Class;
1227-
LLVM_FALLTHROUGH;
1227+
SWIFT_FALLTHROUGH;
12281228
case MetadataKind::Class: {
12291229
// Check if the source is a subclass of the target.
12301230
#if SWIFT_OBJC_INTEROP
@@ -1263,7 +1263,7 @@ swift_dynamicCastMetatypeUnconditionalImpl(const Metadata *sourceType,
12631263
// Get the actual class object.
12641264
sourceType = static_cast<const ObjCClassWrapperMetadata*>(sourceType)
12651265
->Class;
1266-
LLVM_FALLTHROUGH;
1266+
SWIFT_FALLTHROUGH;
12671267
case MetadataKind::Class:
12681268
case MetadataKind::ForeignClass:
12691269
// Check if the source is a subclass of the target.
@@ -2412,7 +2412,7 @@ static bool swift_dynamicCastImpl(OpaqueValue *dest, OpaqueValue *src,
24122412
return _dynamicCastFromAnyHashable(dest, src, srcType,
24132413
targetType, flags);
24142414
}
2415-
LLVM_FALLTHROUGH;
2415+
SWIFT_FALLTHROUGH;
24162416

24172417
case MetadataKind::Enum:
24182418
case MetadataKind::Optional: {
@@ -2527,7 +2527,7 @@ static bool swift_dynamicCastImpl(OpaqueValue *dest, OpaqueValue *src,
25272527
break;
25282528
}
25292529

2530-
LLVM_FALLTHROUGH;
2530+
SWIFT_FALLTHROUGH;
25312531

25322532
// The non-polymorphic types.
25332533
default:

stdlib/public/runtime/Demangle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
517517
}
518518

519519
// Otherwise it requires a tuple wrapper.
520-
LLVM_FALLTHROUGH;
520+
SWIFT_FALLTHROUGH;
521521
}
522522

523523
// This covers both none and multiple parameters.

stdlib/public/runtime/MetadataCache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ class MetadataCacheEntryBase
10761076
case LSK::CompletionQueue:
10771077
// Move the existing completion queue to the cache entry.
10781078
queueEntry->CompletionQueue = LockedStorage.CompletionQueue;
1079-
LLVM_FALLTHROUGH;
1079+
SWIFT_FALLTHROUGH;
10801080

10811081
case LSK::AllocatingThread:
10821082
LockedStorageKind = LSK::QueueEntry;

stdlib/public/runtime/ReflectionMirror.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ auto call(OpaqueValue *passedValue, const Metadata *T, const Metadata *passedTyp
755755
return callClass();
756756
}
757757
}
758-
LLVM_FALLTHROUGH;
758+
SWIFT_FALLTHROUGH;
759759
}
760760

761761
/// TODO: Implement specialized mirror witnesses for all kinds.

0 commit comments

Comments
 (0)