Bug 1814600 - Annotate abort calls as __attribute__((nomerge)) to get clearer line number when crashing on assertion failure. r=gsvelto,yjuglaret

Differential Revision: https://phabricator.services.mozilla.com/D168960
This commit is contained in:
Paul Adenot 2023-11-10 13:54:54 +00:00
parent 6a82880fac
commit 643afe2840
2 changed files with 18 additions and 2 deletions

View File

@ -210,13 +210,13 @@ MOZ_NoReturn(int aLine) {
# define MOZ_REALLY_CRASH(line) \ # define MOZ_REALLY_CRASH(line) \
do { \ do { \
*((volatile int*)MOZ_CRASH_WRITE_ADDR) = line; /* NOLINT */ \ *((volatile int*)MOZ_CRASH_WRITE_ADDR) = line; /* NOLINT */ \
::abort(); \ MOZ_NOMERGE ::abort(); \
} while (false) } while (false)
# else # else
# define MOZ_REALLY_CRASH(line) \ # define MOZ_REALLY_CRASH(line) \
do { \ do { \
*((volatile int*)MOZ_CRASH_WRITE_ADDR) = line; /* NOLINT */ \ *((volatile int*)MOZ_CRASH_WRITE_ADDR) = line; /* NOLINT */ \
abort(); \ MOZ_NOMERGE abort(); \
} while (false) } while (false)
# endif # endif
#endif #endif

View File

@ -88,6 +88,22 @@
# endif # endif
#endif #endif
/**
* Per clang's documentation:
*
* If a statement is marked nomerge and contains call expressions, those call
* expressions inside the statement will not be merged during optimization. This
* attribute can be used to prevent the optimizer from obscuring the source
* location of certain calls.
*
* This is useful to have clearer information on assertion failures.
*/
#if defined(__clang__) && __has_attribute(nomerge)
# define MOZ_NOMERGE __attribute__((nomerge))
#else
# define MOZ_NOMERGE
#endif
/* /*
* MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the * MOZ_NEVER_INLINE is a macro which expands to tell the compiler that the
* method decorated with it must never be inlined, even if the compiler would * method decorated with it must never be inlined, even if the compiler would