Skip to content

Commit de6d393

Browse files
authored
Merge pull request #31622 from compnerd/point-of-noreturn
runtime: add and switch to `SWIFT_NORETURN` (NFC)
2 parents 53055fa + e0b0d20 commit de6d393

File tree

5 files changed

+27
-29
lines changed

5 files changed

+27
-29
lines changed

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(noreturn)
76+
#define SWIFT_NORETURN __attribute__((__noreturn__))
77+
#else
78+
#define SWIFT_NORETURN
79+
#endif
80+
7581
#if __has_attribute(used)
7682
#define SWIFT_USED __attribute__((__used__))
7783
#else

stdlib/public/runtime/Casting.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ swift::swift_getMangledTypeName(const Metadata *type) {
248248
// This is noinline to preserve this frame in stack traces.
249249
// We want "dynamicCastFailure" to appear in crash logs even we crash
250250
// during the diagnostic because some Metadata is invalid.
251-
LLVM_ATTRIBUTE_NORETURN SWIFT_NOINLINE void
251+
SWIFT_NORETURN SWIFT_NOINLINE void
252252
swift::swift_dynamicCastFailure(const void *sourceType, const char *sourceName,
253253
const void *targetType, const char *targetName,
254254
const char *message) {
@@ -260,11 +260,9 @@ swift::swift_dynamicCastFailure(const void *sourceType, const char *sourceName,
260260
message ? message : "");
261261
}
262262

263-
LLVM_ATTRIBUTE_NORETURN
264-
void
265-
swift::swift_dynamicCastFailure(const Metadata *sourceType,
266-
const Metadata *targetType,
267-
const char *message) {
263+
SWIFT_NORETURN void swift::swift_dynamicCastFailure(const Metadata *sourceType,
264+
const Metadata *targetType,
265+
const char *message) {
268266
std::string sourceName = nameForMetadata(sourceType);
269267
std::string targetName = nameForMetadata(targetType);
270268

stdlib/public/runtime/ErrorObject.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,20 @@ SWIFT_RUNTIME_STDLIB_API
206206
void swift_errorRelease(SwiftError *object);
207207

208208
/// Breakpoint hook for debuggers.
209-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API
210-
void swift_willThrow(SWIFT_CONTEXT void *unused,
211-
SWIFT_ERROR_RESULT SwiftError **object);
209+
SWIFT_CC(swift)
210+
SWIFT_RUNTIME_STDLIB_API void
211+
swift_willThrow(SWIFT_CONTEXT void *unused,
212+
SWIFT_ERROR_RESULT SwiftError **object);
212213

213214
/// Halt in response to an error.
214-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API LLVM_ATTRIBUTE_NORETURN
215-
void swift_errorInMain(SwiftError *object);
216-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API LLVM_ATTRIBUTE_NORETURN
217-
void swift_unexpectedError(SwiftError *object,
218-
OpaqueValue *filenameStart,
219-
long filenameLength,
220-
bool isAscii,
221-
unsigned long line);
215+
SWIFT_CC(swift)
216+
SWIFT_RUNTIME_STDLIB_API SWIFT_NORETURN void
217+
swift_errorInMain(SwiftError *object);
218+
219+
SWIFT_CC(swift)
220+
SWIFT_RUNTIME_STDLIB_API SWIFT_NORETURN void
221+
swift_unexpectedError(SwiftError *object, OpaqueValue *filenameStart,
222+
long filenameLength, bool isAscii, unsigned long line);
222223

223224
#if SWIFT_OBJC_INTEROP
224225

stdlib/public/runtime/Errors.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,7 @@ static int swift_vasprintf(char **strp, const char *fmt, va_list ap) {
376376
}
377377

378378
// Report a fatal error to system console, stderr, and crash logs, then abort.
379-
LLVM_ATTRIBUTE_NORETURN
380-
void
381-
swift::fatalError(uint32_t flags, const char *format, ...)
382-
{
379+
SWIFT_NORETURN void swift::fatalError(uint32_t flags, const char *format, ...) {
383380
va_list args;
384381
va_start(args, format);
385382

@@ -419,15 +416,11 @@ swift::warning(uint32_t flags, const char *format, ...)
419416
}
420417

421418
// Crash when a deleted method is called by accident.
422-
SWIFT_RUNTIME_EXPORT
423-
LLVM_ATTRIBUTE_NORETURN
424-
void
425-
swift_deletedMethodError() {
419+
SWIFT_RUNTIME_EXPORT SWIFT_NORETURN void swift_deletedMethodError() {
426420
swift::fatalError(/* flags = */ 0,
427421
"Fatal error: Call of deleted method\n");
428422
}
429423

430-
431424
// Crash due to a retain count overflow.
432425
// FIXME: can't pass the object's address from InlineRefCounts without hacks
433426
void swift::swift_abortRetainOverflow() {

stdlib/public/runtime/Metadata.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5312,9 +5312,9 @@ checkTransitiveCompleteness(const Metadata *initialType) {
53125312
}
53135313

53145314
/// Diagnose a metadata dependency cycle.
5315-
LLVM_ATTRIBUTE_NORETURN
5316-
static void diagnoseMetadataDependencyCycle(const Metadata *start,
5317-
ArrayRef<MetadataDependency> links){
5315+
SWIFT_NORETURN static void
5316+
diagnoseMetadataDependencyCycle(const Metadata *start,
5317+
ArrayRef<MetadataDependency> links) {
53185318
assert(start == links.back().Value);
53195319

53205320
std::string diagnostic =

0 commit comments

Comments
 (0)