Skip to content

Commit ec31346

Browse files
authored
Merge pull request #31629 from compnerd/fall-into-the-gap
runtime: add and switch to `SWIFT_FALLTHROUGH` (NFC)
2 parents 9116646 + a741542 commit ec31346

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

stdlib/public/Reflection/TypeLowering.cpp

+1-1
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

+1-1
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

+16
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.
@@ -133,6 +137,18 @@
133137
#define SWIFT_RUNTIME_EXPORT SWIFT_EXPORT_ATTRIBUTE
134138
#endif
135139

140+
#if __cplusplus > 201402l && __has_cpp_attribute(fallthrough)
141+
#define SWIFT_FALLTHROUGH [[fallthrough]]
142+
#elif __has_cpp_attribute(gnu::fallthrough)
143+
#define SWIFT_FALLTHROUGH [[gnu::fallthrough]]
144+
#elif __has_cpp_attribute(clang::fallthrough)
145+
#define SWIFT_FALLTHROUGH [[clang::fallthrough]]
146+
#elif __has_attribute(fallthrough)
147+
#define SWIFT_FALLTHROUGH __attribute__((__fallthrough__))
148+
#else
149+
#define SWIFT_FALLTHROUGH
150+
#endif
151+
136152

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

stdlib/public/runtime/Casting.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ static bool _dynamicCastToExistential(OpaqueValue *dest,
894894
maybeDeallocateSource(result);
895895
return result;
896896
}
897-
LLVM_FALLTHROUGH;
897+
SWIFT_FALLTHROUGH;
898898

899899
case MetadataKind::Enum:
900900
case MetadataKind::Optional:
@@ -910,7 +910,7 @@ static bool _dynamicCastToExistential(OpaqueValue *dest,
910910
maybeDeallocateSource(success);
911911
return success;
912912
}
913-
LLVM_FALLTHROUGH;
913+
SWIFT_FALLTHROUGH;
914914

915915
default:
916916
return fallbackForNonClass();
@@ -1127,15 +1127,15 @@ swift_dynamicCastMetatypeImpl(const Metadata *sourceType,
11271127
// Get the actual class object.
11281128
targetType = static_cast<const ObjCClassWrapperMetadata*>(targetType)
11291129
->Class;
1130-
LLVM_FALLTHROUGH;
1130+
SWIFT_FALLTHROUGH;
11311131
case MetadataKind::Class:
11321132
// The source value must also be a class; otherwise the cast fails.
11331133
switch (sourceType->getKind()) {
11341134
case MetadataKind::ObjCClassWrapper:
11351135
// Get the actual class object.
11361136
sourceType = static_cast<const ObjCClassWrapperMetadata*>(sourceType)
11371137
->Class;
1138-
LLVM_FALLTHROUGH;
1138+
SWIFT_FALLTHROUGH;
11391139
case MetadataKind::Class: {
11401140
// Check if the source is a subclass of the target.
11411141
#if SWIFT_OBJC_INTEROP
@@ -1171,7 +1171,7 @@ swift_dynamicCastMetatypeImpl(const Metadata *sourceType,
11711171
// Get the actual class object.
11721172
sourceType = static_cast<const ObjCClassWrapperMetadata*>(sourceType)
11731173
->Class;
1174-
LLVM_FALLTHROUGH;
1174+
SWIFT_FALLTHROUGH;
11751175
case MetadataKind::Class:
11761176
case MetadataKind::ForeignClass:
11771177
// Check if the source is a subclass of the target.
@@ -1214,15 +1214,15 @@ swift_dynamicCastMetatypeUnconditionalImpl(const Metadata *sourceType,
12141214
// Get the actual class object.
12151215
targetType = static_cast<const ObjCClassWrapperMetadata*>(targetType)
12161216
->Class;
1217-
LLVM_FALLTHROUGH;
1217+
SWIFT_FALLTHROUGH;
12181218
case MetadataKind::Class:
12191219
// The source value must also be a class; otherwise the cast fails.
12201220
switch (sourceType->getKind()) {
12211221
case MetadataKind::ObjCClassWrapper:
12221222
// Get the actual class object.
12231223
sourceType = static_cast<const ObjCClassWrapperMetadata*>(sourceType)
12241224
->Class;
1225-
LLVM_FALLTHROUGH;
1225+
SWIFT_FALLTHROUGH;
12261226
case MetadataKind::Class: {
12271227
// Check if the source is a subclass of the target.
12281228
#if SWIFT_OBJC_INTEROP
@@ -1261,7 +1261,7 @@ swift_dynamicCastMetatypeUnconditionalImpl(const Metadata *sourceType,
12611261
// Get the actual class object.
12621262
sourceType = static_cast<const ObjCClassWrapperMetadata*>(sourceType)
12631263
->Class;
1264-
LLVM_FALLTHROUGH;
1264+
SWIFT_FALLTHROUGH;
12651265
case MetadataKind::Class:
12661266
case MetadataKind::ForeignClass:
12671267
// Check if the source is a subclass of the target.
@@ -2410,7 +2410,7 @@ static bool swift_dynamicCastImpl(OpaqueValue *dest, OpaqueValue *src,
24102410
return _dynamicCastFromAnyHashable(dest, src, srcType,
24112411
targetType, flags);
24122412
}
2413-
LLVM_FALLTHROUGH;
2413+
SWIFT_FALLTHROUGH;
24142414

24152415
case MetadataKind::Enum:
24162416
case MetadataKind::Optional: {
@@ -2525,7 +2525,7 @@ static bool swift_dynamicCastImpl(OpaqueValue *dest, OpaqueValue *src,
25252525
break;
25262526
}
25272527

2528-
LLVM_FALLTHROUGH;
2528+
SWIFT_FALLTHROUGH;
25292529

25302530
// The non-polymorphic types.
25312531
default:

stdlib/public/runtime/Demangle.cpp

+1-1
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

+1-1
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

+1-1
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)