commit 8976f01f872306fbeeca2cf949fa242711120b85
parent 0a08e3bb618913238d48035d03325910202fe8c1
Author: Cristina Horotan <chorotan@mozilla.com>
Date: Wed, 1 Oct 2025 10:36:51 +0300
Revert "Bug 1990641 - Replace MOZ_NORETURN by [[noreturn]] or _NoReturn r=emilio" on request by dev
This reverts commit 5eeb79e8b1a7d041a08ebeca10e14258719f1b33.
Diffstat:
9 files changed, 42 insertions(+), 25 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 {}
-[[noreturn]] extern MOZ_COLD JS_PUBLIC_API void JS_Assert(const char* s,
+extern MOZ_NORETURN 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 {
- [[noreturn]] MOZ_COLD void crash(const char* reason) { crash_impl(reason); }
- [[noreturn]] MOZ_COLD void crash(size_t size, const char* reason) {
+ MOZ_NORETURN MOZ_COLD void crash(const char* reason) { crash_impl(reason); }
+ MOZ_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:
- [[noreturn]] static MOZ_COLD void crash_impl(const char* reason);
- [[noreturn]] static MOZ_COLD void crash_impl(size_t size, const char* reason);
+ 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);
};
} /* 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> {};
-[[noreturn]] MOZ_COLD MOZ_NEVER_INLINE void ReportBadValueTypeAndCrash(
+MOZ_HAVE_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 [[noreturn]]. But that
+ // We won't reach here because mozalloc_abort() is MOZ_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,13 +15,14 @@
* Terminate this process in such a way that breakpad is triggered, if
* at all possible.
*
- * Note: [[noreturn]] seems to break crash stacks on ARM, so we don't
+ * Note: MOZ_NORETURN seems to break crash stacks on ARM, so we don't
* use that annotation there.
*/
-extern "C"
+extern "C" MFBT_API
#if !defined(__arm__)
- [[noreturn]]
+ MOZ_NORETURN
#endif
- MFBT_API void mozalloc_abort(const char* const msg);
+ 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 __attribute__((__noreturn__))
+# define MOZ_THROW_NORETURN MOZ_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
-[[noreturn]] MFBT_API MOZ_COLD void mozilla::detail::InvalidArrayIndex_CRASH(
+MFBT_API MOZ_NORETURN 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, noreturn]] static MOZ_COLD MOZ_NEVER_INLINE void MOZ_NoReturn(
- int aLine) {
+[[maybe_unused]] static MOZ_COLD MOZ_NORETURN MOZ_NEVER_INLINE void
+MOZ_NoReturn(int aLine) {
*((volatile int*)NULL) = aLine;
TerminateProcess(GetCurrentProcess(), 3);
MOZ_ASSUME_UNREACHABLE_MARKER();
@@ -361,12 +361,7 @@ 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.
*/
-#ifdef __cplusplus
-[[noreturn]]
-#else
-_Noreturn
-#endif
-static MOZ_ALWAYS_INLINE_EVEN_DEBUG MOZ_COLD void MOZ_Crash(
+static MOZ_ALWAYS_INLINE_EVEN_DEBUG MOZ_COLD MOZ_NORETURN 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)
@@ -780,7 +775,7 @@ struct AssertionConditionType {
*/
#ifdef __cplusplus
namespace mozilla::detail {
-[[noreturn]] MFBT_API MOZ_COLD void InvalidArrayIndex_CRASH(size_t aIndex,
+MFBT_API MOZ_NORETURN 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,6 +58,7 @@
* 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
@@ -71,8 +72,12 @@
# 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
@@ -160,11 +165,27 @@
# define MOZ_NEVER_INLINE_DEBUG /* don't inline in opt builds */
#endif
/*
- * MOZ_HAVE_NORETURN_PTR is equivalent to [[noreturn]] but can be set on
- * function pointers.
+ * 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.
*
* 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; }
-[[noreturn]] static void __fastcall patched_BaseThreadInitThunk(
+static MOZ_NORETURN void __fastcall patched_BaseThreadInitThunk(
BOOL aIsInitialThread, void* aStartAddress, void* aThreadParam) {
if (ShouldBlockThread(aStartAddress)) {
aStartAddress = (void*)NopThreadProc;