commit e7e6432de6837c3b93d983cb06834aac860c8af0
parent 6202ec5a7e9088608e3310255c3b402e3a1f2ba5
Author: serge-sans-paille <sguelton@mozilla.com>
Date: Wed, 1 Oct 2025 08:09:20 +0000
Bug 1990641 - Replace MOZ_NORETURN by [[noreturn]] or _NoReturn r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D266076
Diffstat:
9 files changed, 25 insertions(+), 42 deletions(-)
diff --git a/js/public/Utility.h b/js/public/Utility.h
@@ -32,7 +32,7 @@ namespace mozilla {}
/* The private JS engine namespace. */
namespace js {}
-extern MOZ_NORETURN MOZ_COLD JS_PUBLIC_API void JS_Assert(const char* s,
+[[noreturn]] extern MOZ_COLD JS_PUBLIC_API void JS_Assert(const char* s,
const char* file,
int ln);
@@ -308,8 +308,8 @@ namespace js {
/* Disable OOM testing in sections which are not OOM safe. */
struct MOZ_RAII JS_PUBLIC_DATA AutoEnterOOMUnsafeRegion {
- MOZ_NORETURN MOZ_COLD void crash(const char* reason) { crash_impl(reason); }
- MOZ_NORETURN MOZ_COLD void crash(size_t size, const char* reason) {
+ [[noreturn]] MOZ_COLD void crash(const char* reason) { crash_impl(reason); }
+ [[noreturn]] MOZ_COLD void crash(size_t size, const char* reason) {
crash_impl(reason);
}
@@ -344,8 +344,8 @@ struct MOZ_RAII JS_PUBLIC_DATA AutoEnterOOMUnsafeRegion {
bool oomEnabled_;
# endif
private:
- static MOZ_NORETURN MOZ_COLD void crash_impl(const char* reason);
- static MOZ_NORETURN MOZ_COLD void crash_impl(size_t size, const char* reason);
+ [[noreturn]] static MOZ_COLD void crash_impl(const char* reason);
+ [[noreturn]] static MOZ_COLD void crash_impl(size_t size, const char* reason);
};
} /* namespace js */
diff --git a/js/public/Value.h b/js/public/Value.h
@@ -1379,7 +1379,7 @@ template <typename Wrapper>
class HeapOperations<JS::Value, Wrapper>
: public MutableWrappedPtrOperations<JS::Value, Wrapper> {};
-MOZ_HAVE_NORETURN MOZ_COLD MOZ_NEVER_INLINE void ReportBadValueTypeAndCrash(
+[[noreturn]] MOZ_COLD MOZ_NEVER_INLINE void ReportBadValueTypeAndCrash(
const JS::Value& val);
// If the Value is a GC pointer type, call |f| with the pointer cast to that
diff --git a/memory/mozalloc/mozalloc_abort.cpp b/memory/mozalloc/mozalloc_abort.cpp
@@ -89,7 +89,7 @@ extern "C" void abort(void) {
mozalloc_abort(msg);
- // We won't reach here because mozalloc_abort() is MOZ_NORETURN. But that
+ // We won't reach here because mozalloc_abort() is [[noreturn]]. But that
// annotation isn't used on ARM (see mozalloc_abort.h for why) so we add a
// unreachable marker here to avoid a "'noreturn' function does return"
// warning.
diff --git a/memory/mozalloc/mozalloc_abort.h b/memory/mozalloc/mozalloc_abort.h
@@ -15,14 +15,13 @@
* Terminate this process in such a way that breakpad is triggered, if
* at all possible.
*
- * Note: MOZ_NORETURN seems to break crash stacks on ARM, so we don't
+ * Note: [[noreturn]] seems to break crash stacks on ARM, so we don't
* use that annotation there.
*/
-extern "C" MFBT_API
+extern "C"
#if !defined(__arm__)
- MOZ_NORETURN
+ [[noreturn]]
#endif
- void
- mozalloc_abort(const char* const msg);
+ MFBT_API void mozalloc_abort(const char* const msg);
#endif /* ifndef mozilla_mozalloc_abort_h */
diff --git a/memory/mozalloc/throw_gcc.h b/memory/mozalloc/throw_gcc.h
@@ -31,7 +31,7 @@
# endif
# endif
# ifndef MOZ_THROW_NORETURN
-# define MOZ_THROW_NORETURN MOZ_NORETURN
+# define MOZ_THROW_NORETURN __attribute__((__noreturn__))
# endif
// MinGW doesn't appropriately inline these functions in debug builds,
diff --git a/mfbt/Assertions.cpp b/mfbt/Assertions.cpp
@@ -72,7 +72,7 @@ const char* CrashFmtImpl(const char* format, Args&&... args) {
#endif
-MFBT_API MOZ_NORETURN MOZ_COLD void mozilla::detail::InvalidArrayIndex_CRASH(
+[[noreturn]] MFBT_API MOZ_COLD void mozilla::detail::InvalidArrayIndex_CRASH(
size_t aIndex, size_t aLength) {
MOZ_CRASH_UNSAFE_PRINTF("ElementAt(aIndex = %zu, aLength = %zu)", aIndex,
aLength);
diff --git a/mfbt/Assertions.h b/mfbt/Assertions.h
@@ -208,8 +208,8 @@ MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename,
* by MSVC, so doing it this way reduces complexity.)
*/
-[[maybe_unused]] static MOZ_COLD MOZ_NORETURN MOZ_NEVER_INLINE void
-MOZ_NoReturn(int aLine) {
+[[maybe_unused, noreturn]] static MOZ_COLD MOZ_NEVER_INLINE void MOZ_NoReturn(
+ int aLine) {
*((volatile int*)NULL) = aLine;
TerminateProcess(GetCurrentProcess(), 3);
MOZ_ASSUME_UNREACHABLE_MARKER();
@@ -361,7 +361,12 @@ static inline void MOZ_CrashSequence(void* aAddress, intptr_t aLine) {
* to crash-stats and are publicly visible. Firefox data stewards must do data
* review on usages of this macro.
*/
-static MOZ_ALWAYS_INLINE_EVEN_DEBUG MOZ_COLD MOZ_NORETURN void MOZ_Crash(
+#ifdef __cplusplus
+[[noreturn]]
+#else
+_Noreturn
+#endif
+static MOZ_ALWAYS_INLINE_EVEN_DEBUG MOZ_COLD void MOZ_Crash(
const char* aFilename, int aLine, const char* aReason) {
MOZ_FUZZING_HANDLE_CRASH_EVENT4("MOZ_CRASH", aFilename, aLine, aReason);
#if defined(DEBUG) || defined(MOZ_ASAN) || defined(FUZZING)
@@ -775,7 +780,7 @@ struct AssertionConditionType {
*/
#ifdef __cplusplus
namespace mozilla::detail {
-MFBT_API MOZ_NORETURN MOZ_COLD void InvalidArrayIndex_CRASH(size_t aIndex,
+[[noreturn]] MFBT_API MOZ_COLD void InvalidArrayIndex_CRASH(size_t aIndex,
size_t aLength);
} // namespace mozilla::detail
#endif // __cplusplus
diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h
@@ -58,7 +58,6 @@
* for forward compatibility.
*/
# define MOZ_HAVE_NEVER_INLINE __declspec(noinline)
-# define MOZ_HAVE_NORETURN __declspec(noreturn)
#elif defined(__clang__)
/*
* Per Clang documentation, "Note that marketing version numbers should not
@@ -72,12 +71,8 @@
# if __has_attribute(noinline)
# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline))
# endif
-# if __has_attribute(noreturn)
-# define MOZ_HAVE_NORETURN __attribute__((noreturn))
-# endif
#elif defined(__GNUC__)
# define MOZ_HAVE_NEVER_INLINE __attribute__((noinline))
-# define MOZ_HAVE_NORETURN __attribute__((noreturn))
# define MOZ_HAVE_NORETURN_PTR __attribute__((noreturn))
#endif
@@ -165,27 +160,11 @@
# define MOZ_NEVER_INLINE_DEBUG /* don't inline in opt builds */
#endif
/*
- * MOZ_NORETURN, specified at the start of a function declaration, indicates
- * that the given function does not return. (The function definition does not
- * need to be annotated.)
- *
- * MOZ_NORETURN void abort(const char* msg);
- *
- * This modifier permits the compiler to optimize code assuming a call to such a
- * function will never return. It also enables the compiler to avoid spurious
- * warnings about not initializing variables, or about any other seemingly-dodgy
- * operations performed after the function returns.
- *
- * There are two variants. The GCC version of NORETURN may be applied to a
- * function pointer, while for MSVC it may not.
+ * MOZ_HAVE_NORETURN_PTR is equivalent to [[noreturn]] but can be set on
+ * function pointers.
*
* This modifier does not affect the corresponding function's linking behavior.
*/
-#if defined(MOZ_HAVE_NORETURN)
-# define MOZ_NORETURN MOZ_HAVE_NORETURN
-#else
-# define MOZ_NORETURN /* no support */
-#endif
#if defined(MOZ_HAVE_NORETURN_PTR)
# define MOZ_NORETURN_PTR MOZ_HAVE_NORETURN_PTR
#else
diff --git a/toolkit/xre/dllservices/mozglue/WindowsDllBlocklist.cpp b/toolkit/xre/dllservices/mozglue/WindowsDllBlocklist.cpp
@@ -553,7 +553,7 @@ static bool ShouldBlockThread(void* aStartAddress) {
// case there's any magic there that we shouldn't skip.
static DWORD WINAPI NopThreadProc(void* /* aThreadParam */) { return 0; }
-static MOZ_NORETURN void __fastcall patched_BaseThreadInitThunk(
+[[noreturn]] static void __fastcall patched_BaseThreadInitThunk(
BOOL aIsInitialThread, void* aStartAddress, void* aThreadParam) {
if (ShouldBlockThread(aStartAddress)) {
aStartAddress = (void*)NopThreadProc;