Sync third_party/base/immediate_crash.h with Chromium copy
Update to the latest Chromium copy and wrap namespace base inside
namespace pdfium. Adjust third_party/base/check.h to match.
Change-Id: Idfe5a05a84c579b729223fb4209f27b2835dd63a
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/105110
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/third_party/base/check.h b/third_party/base/check.h
index 39d3195..ecfeed8 100644
--- a/third_party/base/check.h
+++ b/third_party/base/check.h
@@ -11,11 +11,11 @@
#include "third_party/base/compiler_specific.h"
#include "third_party/base/immediate_crash.h"
-#define CHECK(condition) \
- do { \
- if (UNLIKELY(!(condition))) { \
- IMMEDIATE_CRASH(); \
- } \
+#define CHECK(condition) \
+ do { \
+ if (UNLIKELY(!(condition))) { \
+ pdfium::base::ImmediateCrash(); \
+ } \
} while (0)
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
diff --git a/third_party/base/immediate_crash.h b/third_party/base/immediate_crash.h
index 658b381..36aca7b 100644
--- a/third_party/base/immediate_crash.h
+++ b/third_party/base/immediate_crash.h
@@ -1,4 +1,4 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
+// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -126,43 +126,29 @@
TRAP_SEQUENCE2_(); \
} while (false)
-// CHECK() and the trap sequence can be invoked from a constexpr function.
-// This could make compilation fail on GCC, as it forbids directly using inline
-// asm inside a constexpr function. However, it allows calling a lambda
-// expression including the same asm.
-// The side effect is that the top of the stacktrace will not point to the
-// calling function, but to this anonymous lambda. This is still useful as the
-// full name of the lambda will typically include the name of the function that
-// calls CHECK() and the debugger will still break at the right line of code.
-#if !defined(COMPILER_GCC)
-
-#define WRAPPED_TRAP_SEQUENCE_() TRAP_SEQUENCE_()
-
+// This version of ALWAYS_INLINE inlines even in is_debug=true.
+// TODO(pbos): See if NDEBUG can be dropped from ALWAYS_INLINE as well, and if
+// so merge. Otherwise document why it cannot inline in debug in
+// base/compiler_specific.h.
+#if defined(COMPILER_GCC)
+#define IMMEDIATE_CRASH_ALWAYS_INLINE inline __attribute__((__always_inline__))
+#elif defined(COMPILER_MSVC)
+#define IMMEDIATE_CRASH_ALWAYS_INLINE __forceinline
#else
+#define IMMEDIATE_CRASH_ALWAYS_INLINE inline
+#endif
-#define WRAPPED_TRAP_SEQUENCE_() \
- do { \
- [] { TRAP_SEQUENCE_(); }(); \
- } while (false)
+namespace pdfium {
+namespace base {
-#endif // !defined(COMPILER_GCC)
-
+[[noreturn]] IMMEDIATE_CRASH_ALWAYS_INLINE void ImmediateCrash() {
+ TRAP_SEQUENCE_();
#if defined(__clang__) || defined(COMPILER_GCC)
-
-// __builtin_unreachable() hints to the compiler that this is noreturn and can
-// be packed in the function epilogue.
-#define IMMEDIATE_CRASH() \
- ({ \
- WRAPPED_TRAP_SEQUENCE_(); \
- __builtin_unreachable(); \
- })
-
-#else
-
-// This is supporting non-chromium user of logging.h to build with MSVC, like
-// pdfium. On MSVC there is no __builtin_unreachable().
-#define IMMEDIATE_CRASH() WRAPPED_TRAP_SEQUENCE_()
-
+ __builtin_unreachable();
#endif // defined(__clang__) || defined(COMPILER_GCC)
+}
+
+} // namespace base
+} // namespace pdfium
#endif // THIRD_PARTY_BASE_IMMEDIATE_CRASH_H_