1 // Copyright 2020 The Chromium Authors 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 8 #include "base/base_export.h" 9 #include "base/check.h" 10 #include "base/compiler_specific.h" 11 #include "base/dcheck_is_on.h" 12 13 // TODO(crbug.com/41493641): Remove once NOTIMPLEMENTED() call sites include 14 // base/notimplemented.h. 15 #include "base/notimplemented.h" 16 17 namespace logging { 18 19 #if CHECK_WILL_STREAM() 20 #define NOTREACHED_INTERNAL_IMPL() ::logging::NotReachedNoreturnError() 21 #else 22 // This function is used to be able to detect NOTREACHED() failures in stack 23 // traces where this symbol is preserved (even if inlined). Its implementation 24 // matches logging::CheckFailure() but intentionally uses a different signature. 25 [[noreturn]] NOMERGE IMMEDIATE_CRASH_ALWAYS_INLINE void NotReachedFailure() { 26 base::ImmediateCrash(); 27 } 28 29 #define NOTREACHED_INTERNAL_IMPL() \ 30 DISCARDING_CHECK_FUNCTION_IMPL(::logging::NotReachedFailure(), false) 31 #endif 32 33 // NOTREACHED() annotates should-be unreachable code. When a base::NotFatalUntil 34 // milestone is provided the instance is non-fatal (dumps without crashing) 35 // until that milestone is hit. That is: `NOTREACHED(base::NotFatalUntil::M120)` 36 // starts crashing in M120. See base/check.h. 37 #define NOTREACHED(...) \ 38 BASE_IF(BASE_IS_EMPTY(__VA_ARGS__), NOTREACHED_INTERNAL_IMPL(), \ 39 LOGGING_CHECK_FUNCTION_IMPL( \ 40 ::logging::NotReachedError::NotReached(__VA_ARGS__), false)) 41 42 // The DUMP_WILL_BE_NOTREACHED() macro provides a convenient way to 43 // non-fatally dump in official builds if ever hit. See DUMP_WILL_BE_CHECK for 44 // suggested usage. 45 #define DUMP_WILL_BE_NOTREACHED() \ 46 ::logging::NotReachedError::DumpWillBeNotReached() 47 48 } // namespace logging 49 50 #endif // BASE_NOTREACHED_H_ 51