blob: c6b94654efea8e98b0459296185d24464db1ce19 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2020 The Chromium Authors
Hans Wennborg0472f8c2020-04-23 19:27:272// 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 Sanders6e709942022-04-05 06:49:268#include "base/base_export.h"
Hans Wennborg0472f8c2020-04-23 19:27:279#include "base/check.h"
Peter Boström7c6383002024-09-10 11:15:3510#include "base/compiler_specific.h"
David Sandersfc1f17fa2022-04-15 00:15:4911#include "base/dcheck_is_on.h"
Hans Wennborg0472f8c2020-04-23 19:27:2712
Hans Wennborg0472f8c2020-04-23 19:27:2713namespace logging {
14
Peter Boström92cdf19b2023-02-06 18:52:2915#if CHECK_WILL_STREAM()
Peter Boström9c1504d2024-11-12 01:06:1316#define NOTREACHED_INTERNAL_IMPL() ::logging::NotReachedNoreturnError()
Peter Boström92cdf19b2023-02-06 18:52:2917#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öm7c6383002024-09-10 11:15:3521[[noreturn]] NOMERGE IMMEDIATE_CRASH_ALWAYS_INLINE void NotReachedFailure() {
Peter Boström92cdf19b2023-02-06 18:52:2922 base::ImmediateCrash();
23}
24
Peter Boström9c1504d2024-11-12 01:06:1325#define NOTREACHED_INTERNAL_IMPL() \
Peter Boströmf9d97ed92024-11-26 19:12:3026 DISCARDING_CHECK_FUNCTION_IMPL(::logging::NotReachedFailure(), false)
Peter Boström92cdf19b2023-02-06 18:52:2927#endif
28
Peter Boström006c93b2024-08-06 00:38:3929// 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öm9c1504d2024-11-12 01:06:1333#define NOTREACHED(...) \
34 BASE_IF(BASE_IS_EMPTY(__VA_ARGS__), NOTREACHED_INTERNAL_IMPL(), \
35 LOGGING_CHECK_FUNCTION_IMPL( \
Peter Boström61831cb2024-05-22 21:32:5336 ::logging::NotReachedError::NotReached(__VA_ARGS__), false))
37
Peter Boströmcb0d53062024-06-04 18:45:3138// The DUMP_WILL_BE_NOTREACHED() macro provides a convenient way to
Peter Boströmbf475822023-05-17 17:17:5039// non-fatally dump in official builds if ever hit. See DUMP_WILL_BE_CHECK for
40// suggested usage.
Peter Boströmcb0d53062024-06-04 18:45:3141#define DUMP_WILL_BE_NOTREACHED() \
Peter Boström7b1ecd862024-11-28 02:50:4042 ::logging::NotReachedError::DumpWillBeNotReached()
Peter Boströmbf475822023-05-17 17:17:5043
Hans Wennborg0472f8c2020-04-23 19:27:2744} // namespace logging
45
46#endif // BASE_NOTREACHED_H_