Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Hans Wennborg | 0472f8c | 2020-04-23 19:27:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_NOTREACHED_H_ |
| 6 | #define BASE_NOTREACHED_H_ |
| 7 | |
David Sanders | 6e70994 | 2022-04-05 06:49:26 | [diff] [blame] | 8 | #include "base/base_export.h" |
Hans Wennborg | 0472f8c | 2020-04-23 19:27:27 | [diff] [blame] | 9 | #include "base/check.h" |
Peter Boström | 7c638300 | 2024-09-10 11:15:35 | [diff] [blame] | 10 | #include "base/compiler_specific.h" |
David Sanders | fc1f17fa | 2022-04-15 00:15:49 | [diff] [blame] | 11 | #include "base/dcheck_is_on.h" |
Hans Wennborg | 0472f8c | 2020-04-23 19:27:27 | [diff] [blame] | 12 | |
Hans Wennborg | 0472f8c | 2020-04-23 19:27:27 | [diff] [blame] | 13 | namespace logging { |
| 14 | |
Peter Boström | 92cdf19b | 2023-02-06 18:52:29 | [diff] [blame] | 15 | #if CHECK_WILL_STREAM() |
Peter Boström | 9c1504d | 2024-11-12 01:06:13 | [diff] [blame] | 16 | #define NOTREACHED_INTERNAL_IMPL() ::logging::NotReachedNoreturnError() |
Peter Boström | 92cdf19b | 2023-02-06 18:52:29 | [diff] [blame] | 17 | #else |
| 18 | // This function is used to be able to detect NOTREACHED() failures in stack |
| 19 | // traces where this symbol is preserved (even if inlined). Its implementation |
| 20 | // matches logging::CheckFailure() but intentionally uses a different signature. |
Peter Boström | 7c638300 | 2024-09-10 11:15:35 | [diff] [blame] | 21 | [[noreturn]] NOMERGE IMMEDIATE_CRASH_ALWAYS_INLINE void NotReachedFailure() { |
Peter Boström | 92cdf19b | 2023-02-06 18:52:29 | [diff] [blame] | 22 | base::ImmediateCrash(); |
| 23 | } |
| 24 | |
Peter Boström | 9c1504d | 2024-11-12 01:06:13 | [diff] [blame] | 25 | #define NOTREACHED_INTERNAL_IMPL() \ |
Peter Boström | f9d97ed9 | 2024-11-26 19:12:30 | [diff] [blame] | 26 | DISCARDING_CHECK_FUNCTION_IMPL(::logging::NotReachedFailure(), false) |
Peter Boström | 92cdf19b | 2023-02-06 18:52:29 | [diff] [blame] | 27 | #endif |
| 28 | |
Peter Boström | 006c93b | 2024-08-06 00:38:39 | [diff] [blame] | 29 | // NOTREACHED() annotates should-be unreachable code. When a base::NotFatalUntil |
| 30 | // milestone is provided the instance is non-fatal (dumps without crashing) |
| 31 | // until that milestone is hit. That is: `NOTREACHED(base::NotFatalUntil::M120)` |
| 32 | // starts crashing in M120. See base/check.h. |
Peter Boström | 9c1504d | 2024-11-12 01:06:13 | [diff] [blame] | 33 | #define NOTREACHED(...) \ |
| 34 | BASE_IF(BASE_IS_EMPTY(__VA_ARGS__), NOTREACHED_INTERNAL_IMPL(), \ |
| 35 | LOGGING_CHECK_FUNCTION_IMPL( \ |
Peter Boström | 61831cb | 2024-05-22 21:32:53 | [diff] [blame] | 36 | ::logging::NotReachedError::NotReached(__VA_ARGS__), false)) |
| 37 | |
Peter Boström | cb0d5306 | 2024-06-04 18:45:31 | [diff] [blame] | 38 | // The DUMP_WILL_BE_NOTREACHED() macro provides a convenient way to |
Peter Boström | bf47582 | 2023-05-17 17:17:50 | [diff] [blame] | 39 | // non-fatally dump in official builds if ever hit. See DUMP_WILL_BE_CHECK for |
| 40 | // suggested usage. |
Peter Boström | cb0d5306 | 2024-06-04 18:45:31 | [diff] [blame] | 41 | #define DUMP_WILL_BE_NOTREACHED() \ |
Peter Boström | 7b1ecd86 | 2024-11-28 02:50:40 | [diff] [blame] | 42 | ::logging::NotReachedError::DumpWillBeNotReached() |
Peter Boström | bf47582 | 2023-05-17 17:17:50 | [diff] [blame] | 43 | |
Hans Wennborg | 0472f8c | 2020-04-23 19:27:27 | [diff] [blame] | 44 | } // namespace logging |
| 45 | |
| 46 | #endif // BASE_NOTREACHED_H_ |