Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/google/protobuf/port_def.inc is written in an unsupported language. File is not indexed.

0001 // -*- c++ -*-
0002 // Protocol Buffers - Google's data interchange format
0003 // Copyright 2008 Google Inc.  All rights reserved.
0004 //
0005 // Use of this source code is governed by a BSD-style
0006 // license that can be found in the LICENSE file or at
0007 // https://developers.google.com/open-source/licenses/bsd
0008 
0009 // This file defines common macros that are used in protobuf.
0010 //
0011 // To hide these definitions from the outside world (and to prevent collisions
0012 // if more than one version of protobuf is #included in the same project) you
0013 // must follow this pattern when #including port_def.inc in a header file:
0014 //
0015 // #include "other_header.h"
0016 // #include "message.h"
0017 // // etc.
0018 //
0019 // #include "port_def.inc"  // MUST be last header included
0020 //
0021 // // Definitions for this header.
0022 //
0023 // #include "port_undef.inc"
0024 //
0025 // This is a textual header with no include guard, because we want to
0026 // detect/prohibit anytime it is #included twice without a corresponding
0027 // #undef.
0028 
0029 #ifdef PROTOBUF_PORT_
0030 #error "port_def.inc included multiple times"
0031 #endif
0032 #define PROTOBUF_PORT_
0033 #include "absl/base/attributes.h"
0034 #include "absl/base/config.h"
0035 #include "absl/base/macros.h"
0036 
0037 // The definitions in this file are intended to be portable across Clang,
0038 // GCC, and MSVC. Function-like macros are usable without an #ifdef guard.
0039 // Syntax macros (for example, attributes) are always defined, although
0040 // they may be empty.
0041 //
0042 // Some definitions rely on the NDEBUG macro and/or (in MSVC) _DEBUG:
0043 // - https://en.cppreference.com/w/c/error/assert
0044 // - https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros#microsoft-specific-predefined-macros
0045 //
0046 // References for predefined macros:
0047 // - Standard: https://en.cppreference.com/w/cpp/preprocessor/replace
0048 // - Clang: https://clang.llvm.org/docs/LanguageExtensions.html
0049 //          (see also GCC predefined macros)
0050 // - GCC: https://gcc.gnu.org/onlinedocs/cpp/Predefined-Macros.html
0051 // - MSVC: https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros
0052 // - Interactive (Clang/GCC only): https://www.compiler-explorer.com/z/hc6jKd3sj
0053 //
0054 // References for attributes (and extension attributes):
0055 // - Standard: https://en.cppreference.com/w/cpp/language/attributes
0056 // - Clang: https://clang.llvm.org/docs/AttributeReference.html
0057 // - GCC: https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html
0058 //        (see Clang attribute docs as well)
0059 //
0060 // References for standard C++ language conformance (and minimum versions):
0061 // - Clang: https://clang.llvm.org/cxx_status.html
0062 // - GCC: https://gcc.gnu.org/projects/cxx-status.html
0063 // - MSVC: https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance
0064 //
0065 // Historical release notes (which can help to determine minimum versions):
0066 // - Clang: https://releases.llvm.org/
0067 // - GCC: https://gcc.gnu.org/releases.html
0068 // - MSVC: https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-history
0069 //         https://docs.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-history
0070 
0071 // Portable check for gcc-style atomic built-ins
0072 #if ABSL_HAVE_BUILTIN(__atomic_load_n)
0073 #define PROTOBUF_BUILTIN_ATOMIC 1
0074 #endif
0075 
0076 // Portable check for GCC minimum version:
0077 // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
0078 #if defined(__GNUC__) && defined(__GNUC_MINOR__) \
0079     && defined(__GNUC_PATCHLEVEL__)
0080 #  define PROTOBUF_GNUC_MIN(x, y) \
0081   (__GNUC__ > (x) || (__GNUC__ == (x) && __GNUC_MINOR__ >= (y)))
0082 #else
0083 #  define PROTOBUF_GNUC_MIN(x, y) 0
0084 #endif
0085 
0086 #if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__)
0087 #define PROTOBUF_CLANG_MIN(x, y) \
0088   (__clang_major__ > (x) || (__clang_major__ == (x) && __clang_minor__ >= (y)))
0089 #else
0090 #define PROTOBUF_CLANG_MIN(x, y) 0
0091 #endif
0092 
0093 // Portable check for MSVC minimum version:
0094 // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros
0095 #if defined(_MSC_VER)
0096 #define PROTOBUF_MSC_VER_MIN(x) (_MSC_VER >= x)
0097 #else
0098 #define PROTOBUF_MSC_VER_MIN(x) 0
0099 #endif
0100 
0101 // Portable check for minimum C++ language version:
0102 // https://en.cppreference.com/w/cpp/preprocessor/replace
0103 // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros
0104 #if !defined(_MSVC_LANG)
0105 #define PROTOBUF_CPLUSPLUS_MIN(x) (__cplusplus >= x)
0106 #else
0107 #define PROTOBUF_CPLUSPLUS_MIN(x) (_MSVC_LANG >= x)
0108 #endif
0109 
0110 // Check minimum Protobuf support defined at:
0111 // https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md
0112 #ifdef __clang__
0113 static_assert(PROTOBUF_CLANG_MIN(6, 0), "Protobuf only supports Clang 6.0 and newer.");
0114 #elif defined(__GNUC__)
0115 static_assert(PROTOBUF_GNUC_MIN(7, 3), "Protobuf only supports GCC 7.3 and newer.");
0116 #elif defined(_MSVC_LANG)
0117 static_assert(PROTOBUF_MSC_VER_MIN(1910), "Protobuf only supports MSVC 2017 and newer.");
0118 #endif
0119 static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and newer.");
0120 
0121 // Check minimum Abseil version.
0122 #if defined(ABSL_LTS_RELEASE_VERSION) && defined(ABSL_LTS_RELEASE_PATCH_LEVEL)
0123 #define PROTOBUF_ABSL_MIN(x, y)      \
0124   (ABSL_LTS_RELEASE_VERSION > (x) || \
0125    (ABSL_LTS_RELEASE_VERSION == (x) && ABSL_LTS_RELEASE_PATCH_LEVEL >= (y)))
0126 #else
0127 // If we can't find an Abseil version, it's either not installed at all (which
0128 // should trigger cmake errors), using a non-LTS release, or just isn't used in
0129 // this file.
0130 #define PROTOBUF_ABSL_MIN(x, y) 1
0131 #endif
0132 
0133 static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
0134               "Protobuf only supports Abseil version 20230125.3 and newer.");
0135 
0136 // Future versions of protobuf will include breaking changes to some APIs.
0137 // This macro can be set to enable these API changes ahead of time, so that
0138 // user code can be updated before upgrading versions of protobuf.
0139 
0140 #ifdef PROTOBUF_FUTURE_BREAKING_CHANGES
0141 
0142 // Used for descriptor proto extension declarations.
0143 // Owner: shaod@, gberg@
0144 #define PROTOBUF_FUTURE_DESCRIPTOR_EXTENSION_DECL 1
0145 
0146 #endif
0147 
0148 #ifdef PROTOBUF_MINIMUM_EDITION
0149 #error PROTOBUF_MINIMUM_EDITION was previously defined
0150 #endif
0151 #define PROTOBUF_MINIMUM_EDITION EDITION_PROTO2
0152 
0153 #ifdef PROTOBUF_MAXIMUM_EDITION
0154 #error PROTOBUF_MAXIMUM_EDITION was previously defined
0155 #endif
0156 #define PROTOBUF_MAXIMUM_EDITION EDITION_2023
0157 
0158 #ifdef PROTOBUF_ALWAYS_INLINE
0159 #error PROTOBUF_ALWAYS_INLINE was previously defined
0160 #endif
0161 // For functions we want to force inline.
0162 #if defined(PROTOBUF_NO_INLINE)
0163 # define PROTOBUF_ALWAYS_INLINE
0164 #elif defined(__GNUC__)
0165 # define PROTOBUF_ALWAYS_INLINE __attribute__((always_inline))
0166 #elif defined(_MSC_VER)
0167 # define PROTOBUF_ALWAYS_INLINE __forceinline
0168 #else
0169 # define PROTOBUF_ALWAYS_INLINE
0170 #endif
0171 
0172 #ifdef PROTOBUF_ALWAYS_INLINE_CALL
0173 #error PROTOBUF_ALWAYS_INLINE_CALL was previously defined
0174 #endif
0175 // For functions we want to force inline from the caller, instead of in the
0176 // declaration of the callee.
0177 // This is useful for lambdas where it is not easy to specify ALWAYS_INLINE.
0178 // Use like:
0179 //   PROTOBUF_ALWAYS_INLINE_CALL res = SomeFunc(args...);
0180 #if defined(__clang__) && !defined(PROTOBUF_NO_INLINE_CALL) && \
0181     ABSL_HAVE_CPP_ATTRIBUTE(clang::always_inline)
0182 #define PROTOBUF_ALWAYS_INLINE_CALL [[clang::always_inline]]
0183 #else
0184 #define PROTOBUF_ALWAYS_INLINE_CALL
0185 #endif
0186 
0187 #ifdef PROTOBUF_NDEBUG_INLINE
0188 #error PROTOBUF_NDEBUG_INLINE was previously defined
0189 #endif
0190 // Avoid excessive inlining in non-optimized builds. Without other optimizations
0191 // the inlining is not going to provide benefits anyway and the huge resulting
0192 // functions, especially in the proto-generated serialization functions, produce
0193 // stack frames so large that many tests run into stack overflows (b/32192897).
0194 #if defined(NDEBUG) || (defined(_MSC_VER) && !defined(_DEBUG))
0195 # define PROTOBUF_NDEBUG_INLINE PROTOBUF_ALWAYS_INLINE
0196 #else
0197 # define PROTOBUF_NDEBUG_INLINE
0198 #endif
0199 
0200 // Note that PROTOBUF_NOINLINE is an attribute applied to functions, to prevent
0201 // them from being inlined by the compiler. This is different from
0202 // PROTOBUF_NO_INLINE, which is a user-supplied macro that disables forced
0203 // inlining by PROTOBUF_(ALWAYS|NDEBUG)_INLINE.
0204 //
0205 // For forward-declared functions, make sure to apply PROTOBUF_NOINLINE to all
0206 // the declarations, not just the definition, or else whole-program optimization
0207 // may not honor the attribute.
0208 #ifdef PROTOBUF_NOINLINE
0209 #error PROTOBUF_NOINLINE was previously defined
0210 #endif
0211 #if defined(__GNUC__)
0212 # define PROTOBUF_NOINLINE __attribute__((noinline))
0213 #elif defined(_MSC_VER)
0214 // Seems to have been around since at least Visual Studio 2005
0215 # define PROTOBUF_NOINLINE __declspec(noinline)
0216 #endif
0217 
0218 #ifdef PROTOBUF_MUSTTAIL
0219 #error PROTOBUF_MUSTTAIL was previously defined
0220 #endif
0221 #ifdef PROTOBUF_TAILCALL
0222 #error PROTOBUF_TAILCALL was previously defined
0223 #endif
0224 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::musttail) && !defined(__arm__) &&  \
0225     !defined(_ARCH_PPC) && !defined(__wasm__) &&                      \
0226     !(defined(_MSC_VER) && defined(_M_IX86)) && !defined(__i386__)
0227 // Compilation fails on ARM32: b/195943306
0228 // Compilation fails on powerpc64le: b/187985113
0229 // Compilation fails on X86 Windows:
0230 // https://github.com/llvm/llvm-project/issues/53271
0231 #define PROTOBUF_MUSTTAIL [[clang::musttail]]
0232 #define PROTOBUF_TAILCALL true
0233 #else
0234 #define PROTOBUF_MUSTTAIL
0235 #define PROTOBUF_TAILCALL false
0236 #endif
0237 
0238 #ifdef PROTOBUF_CC
0239 #error PROTOBUF_CC was previously defined
0240 #endif
0241 #define PROTOBUF_CC
0242 
0243 #if defined(__clang__)
0244 #define PROTOBUF_IGNORE_DEPRECATION_START                     \
0245   _Pragma("clang diagnostic push")                                  \
0246   _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
0247 #define PROTOBUF_IGNORE_DEPRECATION_STOP                     \
0248   _Pragma("clang diagnostic pop")
0249 #elif defined(__GNUC__)
0250 #define PROTOBUF_IGNORE_DEPRECATION_START                     \
0251   _Pragma("GCC diagnostic push")                                  \
0252   _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
0253 #define PROTOBUF_IGNORE_DEPRECATION_STOP                     \
0254   _Pragma("GCC diagnostic pop")
0255 #else
0256 #define PROTOBUF_IGNORE_DEPRECATION_START
0257 #define PROTOBUF_IGNORE_DEPRECATION_STOP
0258 #endif
0259 
0260 #ifdef PROTOBUF_RTTI
0261 #error PROTOBUF_RTTI was previously defined
0262 #endif
0263 #if defined(GOOGLE_PROTOBUF_NO_RTTI) && GOOGLE_PROTOBUF_NO_RTTI
0264 // A user-provided definition GOOGLE_PROTOBUF_NO_RTTI=1 disables RTTI.
0265 #define PROTOBUF_RTTI 0
0266 #elif defined(__cpp_rtti)
0267 // https://en.cppreference.com/w/cpp/feature_test
0268 #define PROTOBUF_RTTI 1
0269 #elif ABSL_HAVE_FEATURE(cxx_rtti)
0270 // https://clang.llvm.org/docs/LanguageExtensions.html#c-rtti
0271 #define PROTOBUF_RTTI 1
0272 #elif defined(__GXX_RTTI)
0273 // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
0274 #define PROTOBUF_RTTI 1
0275 #elif defined(_CPPRTTI)
0276 // https://docs.microsoft.com/en-us/cpp/build/reference/gr-enable-run-time-type-information
0277 #define PROTOBUF_RTTI 1
0278 #else
0279 #define PROTOBUF_RTTI 0
0280 #endif
0281 
0282 // Returns the offset of the given field within the given aggregate type.
0283 // This is equivalent to the ANSI C offsetof() macro.  However, according
0284 // to the C++ standard, offsetof() only works on POD types, and GCC
0285 // enforces this requirement with a warning.  In practice, this rule is
0286 // unnecessarily strict; there is probably no compiler or platform on
0287 // which the offsets of the direct fields of a class are non-constant.
0288 // Fields inherited from superclasses *can* have non-constant offsets,
0289 // but that's not what this macro will be used for.
0290 #ifdef PROTOBUF_FIELD_OFFSET
0291 #error PROTOBUF_FIELD_OFFSET was previously defined
0292 #endif
0293 #if defined(__clang__)
0294 // For Clang we use __builtin_offsetof() and suppress the warning,
0295 // to avoid Control Flow Integrity and UBSan vptr sanitizers from
0296 // crashing while trying to validate the invalid reinterpret_casts.
0297 #define PROTOBUF_FIELD_OFFSET(TYPE, FIELD)                   \
0298   _Pragma("clang diagnostic push")                           \
0299   _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
0300   __builtin_offsetof(TYPE, FIELD)                            \
0301   _Pragma("clang diagnostic pop")
0302 #elif defined(__GNUC__)
0303 #define PROTOBUF_FIELD_OFFSET(TYPE, FIELD) __builtin_offsetof(TYPE, FIELD)
0304 #else  // defined(__clang__)
0305 // Note that we calculate relative to the pointer value 16 here since if we
0306 // just use zero, GCC complains about dereferencing a NULL pointer.  We
0307 // choose 16 rather than some other number just in case the compiler would
0308 // be confused by an unaligned pointer.
0309 #define PROTOBUF_FIELD_OFFSET(TYPE, FIELD)                                \
0310   static_cast< ::uint32_t>(reinterpret_cast<const char*>(                   \
0311                              &reinterpret_cast<const TYPE*>(16)->FIELD) - \
0312                          reinterpret_cast<const char*>(16))
0313 #endif
0314 
0315 #ifdef PROTOBUF_EXPORT
0316 #error PROTOBUF_EXPORT was previously defined
0317 #endif
0318 
0319 #if defined(PROTOBUF_USE_DLLS) && defined(_MSC_VER)
0320 # if defined(LIBPROTOBUF_EXPORTS)
0321 #  define PROTOBUF_EXPORT __declspec(dllexport)
0322 #  define PROTOBUF_EXPORT_TEMPLATE_DECLARE
0323 #  define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllexport)
0324 # else
0325 #  define PROTOBUF_EXPORT __declspec(dllimport)
0326 #  define PROTOBUF_EXPORT_TEMPLATE_DECLARE
0327 #  define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllimport)
0328 # endif  // defined(LIBPROTOBUF_EXPORTS)
0329 #elif defined(PROTOBUF_USE_DLLS) && defined(LIBPROTOBUF_EXPORTS)
0330 # define PROTOBUF_EXPORT __attribute__((visibility("default")))
0331 # define PROTOBUF_EXPORT_TEMPLATE_DECLARE __attribute__((visibility("default")))
0332 # define PROTOBUF_EXPORT_TEMPLATE_DEFINE
0333 #else
0334 # define PROTOBUF_EXPORT
0335 # define PROTOBUF_EXPORT_TEMPLATE_DECLARE
0336 # define PROTOBUF_EXPORT_TEMPLATE_DEFINE
0337 #endif
0338 
0339 #ifdef PROTOC_EXPORT
0340 #error PROTOC_EXPORT was previously defined
0341 #endif
0342 
0343 #if defined(PROTOBUF_USE_DLLS) && defined(_MSC_VER)
0344 # if defined(LIBPROTOC_EXPORTS)
0345 #  define PROTOC_EXPORT __declspec(dllexport)
0346 # else
0347 #  define PROTOC_EXPORT __declspec(dllimport)
0348 # endif  // defined(LIBPROTOC_EXPORTS)
0349 #elif defined(PROTOBUF_USE_DLLS) && defined(LIBPROTOC_EXPORTS)
0350 # define PROTOC_EXPORT __attribute__((visibility("default")))
0351 #else
0352 # define PROTOC_EXPORT
0353 #endif
0354 
0355 #if defined(PROTOBUF_PREDICT_TRUE) || defined(PROTOBUF_PREDICT_FALSE)
0356 #error PROTOBUF_PREDICT_(TRUE|FALSE) was previously defined
0357 #endif
0358 #if defined(__GNUC__)
0359 # define PROTOBUF_PREDICT_TRUE(x) (__builtin_expect(false || (x), true))
0360 # define PROTOBUF_PREDICT_FALSE(x) (__builtin_expect(false || (x), false))
0361 #else
0362 # define PROTOBUF_PREDICT_TRUE(x) (x)
0363 # define PROTOBUF_PREDICT_FALSE(x) (x)
0364 #endif
0365 
0366 #ifdef PROTOBUF_NODISCARD
0367 #error PROTOBUF_NODISCARD was previously defined
0368 #endif
0369 #if ABSL_HAVE_CPP_ATTRIBUTE(nodiscard) && PROTOBUF_CPLUSPLUS_MIN(201703L)
0370 #define PROTOBUF_NODISCARD [[nodiscard]]
0371 #elif ABSL_HAVE_ATTRIBUTE(warn_unused_result) || defined(__GNUC__)
0372 #define PROTOBUF_NODISCARD __attribute__((warn_unused_result))
0373 #else
0374 #define PROTOBUF_NODISCARD
0375 #endif
0376 
0377 #ifdef PROTOBUF_RESTRICT
0378 #error PROTOBUF_RESTRICT was previously defined
0379 #endif
0380 #if defined( __clang__) || defined(__GNUC__)
0381 #define PROTOBUF_RESTRICT __restrict
0382 #else
0383 #define PROTOBUF_RESTRICT
0384 #endif
0385 
0386 #ifdef PROTOBUF_FORCE_COPY_IN_RELEASE
0387 #error PROTOBUF_FORCE_COPY_IN_RELEASE was previously defined
0388 #endif
0389 
0390 #ifdef PROTOBUF_FORCE_COPY_IN_SWAP
0391 #error PROTOBUF_FORCE_COPY_IN_SWAP was previously defined
0392 #endif
0393 
0394 #ifdef PROTOBUF_FORCE_COPY_IN_MOVE
0395 #error PROTOBUF_FORCE_COPY_IN_MOVE was previously defined
0396 #endif
0397 
0398 #ifdef PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG
0399 #error PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG was previously defined
0400 #endif
0401 
0402 // Force copy the default string to a string field so that non-optimized builds
0403 // have harder-to-rely-on address stability.
0404 #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
0405 #error PROTOBUF_FORCE_COPY_DEFAULT_STRING was previously defined
0406 #endif
0407 
0408 #ifdef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION
0409 #error PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION was previously defined
0410 #endif
0411 
0412 // Specify memory alignment for structs, classes, etc.
0413 // Use like:
0414 //   class PROTOBUF_ALIGNAS(16) MyClass { ... }
0415 //   PROTOBUF_ALIGNAS(16) int array[4];
0416 //
0417 // In most places you can use the C++11 keyword "alignas", which is preferred.
0418 //
0419 // But compilers have trouble mixing __attribute__((...)) syntax with
0420 // alignas(...) syntax.
0421 //
0422 // Doesn't work in clang or gcc:
0423 //   struct alignas(16) __attribute__((packed)) S { char c; };
0424 // Works in clang but not gcc:
0425 //   struct __attribute__((packed)) alignas(16) S2 { char c; };
0426 // Works in clang and gcc:
0427 //   struct alignas(16) S3 { char c; } __attribute__((packed));
0428 //
0429 // There are also some attributes that must be specified *before* a class
0430 // definition: visibility (used for exporting functions/classes) is one of
0431 // these attributes. This means that it is not possible to use alignas() with a
0432 // class that is marked as exported.
0433 #ifdef PROTOBUF_ALIGNAS
0434 #error PROTOBUF_ALIGNAS was previously defined
0435 #endif
0436 #if defined(_MSC_VER)
0437 #define PROTOBUF_ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
0438 #elif defined(__GNUC__)
0439 #define PROTOBUF_ALIGNAS(byte_alignment) \
0440   __attribute__((aligned(byte_alignment)))
0441 #else
0442 #define PROTOBUF_ALIGNAS(byte_alignment) alignas(byte_alignment)
0443 #endif
0444 
0445 #ifdef PROTOBUF_THREAD_LOCAL
0446 #error PROTOBUF_THREAD_LOCAL was previously defined
0447 #endif
0448 #if defined(_MSC_VER)
0449 #define PROTOBUF_THREAD_LOCAL __declspec(thread)
0450 #else
0451 #define PROTOBUF_THREAD_LOCAL __thread
0452 #endif
0453 
0454 #ifdef PROTOBUF_CONSTINIT
0455 #error PROTOBUF_CONSTINIT was previously defined
0456 #endif
0457 
0458 // Lexan sets both MSV_VER and clang, so handle it with the clang path.
0459 #if defined(_MSC_VER) && !defined(__clang__)
0460 // MSVC 17 currently seems to raise an error about constant-initialized pointers.
0461 # if PROTOBUF_MSC_VER_MIN(1930)
0462 #  define PROTOBUF_CONSTINIT
0463 #  define PROTOBUF_CONSTEXPR constexpr
0464 # endif
0465 #elif defined(__GNUC__) && !defined(__clang__)
0466 // GCC doesn't support constinit aggregate initialization of absl::Cord.
0467 # if PROTOBUF_GNUC_MIN(12, 2)
0468 #  define PROTOBUF_CONSTINIT
0469 #  define PROTOBUF_CONSTEXPR constexpr
0470 # endif
0471 #else
0472 # if defined(__cpp_constinit) && !defined(__CYGWIN__)
0473 #  define PROTOBUF_CONSTINIT constinit
0474 #  define PROTOBUF_CONSTEXPR constexpr
0475 #  define PROTOBUF_CONSTINIT_DEFAULT_INSTANCES
0476 // Some older Clang versions incorrectly raise an error about
0477 // constant-initializing weak default instance pointers. Versions 12.0 and
0478 // higher seem to work, except that XCode 12.5.1 shows the error even though it
0479 // uses Clang 12.0.5.
0480 #elif !defined(__CYGWIN__) && !defined(__MINGW32__) &&                 \
0481     ABSL_HAVE_CPP_ATTRIBUTE(clang::require_constant_initialization) && \
0482     ((defined(__APPLE__) && PROTOBUF_CLANG_MIN(13, 0)) ||              \
0483      (!defined(__APPLE__) && PROTOBUF_CLANG_MIN(12, 0)))
0484 #  define PROTOBUF_CONSTINIT [[clang::require_constant_initialization]]
0485 #  define PROTOBUF_CONSTEXPR constexpr
0486 #  define PROTOBUF_CONSTINIT_DEFAULT_INSTANCES
0487 # endif
0488 #endif
0489 
0490 #ifndef PROTOBUF_CONSTINIT
0491 #define PROTOBUF_CONSTINIT
0492 #define PROTOBUF_CONSTEXPR
0493 #endif
0494 
0495 // Some globals with an empty non-trivial destructor are annotated with
0496 // no_destroy for performance reasons. It reduces the cost of these globals in
0497 // non-opt mode and under sanitizers.
0498 #ifdef PROTOBUF_ATTRIBUTE_NO_DESTROY
0499 #error PROTOBUF_ATTRIBUTE_NO_DESTROY was previously defined
0500 #endif
0501 #if ABSL_HAVE_CPP_ATTRIBUTE(clang::no_destroy)
0502 #define PROTOBUF_ATTRIBUTE_NO_DESTROY [[clang::no_destroy]]
0503 #else
0504 #define PROTOBUF_ATTRIBUTE_NO_DESTROY
0505 #endif
0506 
0507 // Protobuf extensions and reflection require registration of the protos linked
0508 // in the binary. Not until everything is registered does the runtime have a
0509 // complete view on all protos. When code is using reflection or extensions
0510 // in between registration calls this can lead to surprising behavior. By
0511 // having the registration run first we mitigate this scenario.
0512 // Highest priority is 101. We use 102 for registration, to allow code that
0513 // really wants to higher priority to still beat us. Some initialization happens
0514 // at higher priority, though, since it is needed before registration.
0515 #ifdef PROTOBUF_ATTRIBUTE_INIT_PRIORITY1
0516 #error PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 was previously defined
0517 #endif
0518 #ifdef PROTOBUF_ATTRIBUTE_INIT_PRIORITY2
0519 #error PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 was previously defined
0520 #endif
0521 #if defined(__GNUC__) && (!defined(__APPLE__) || defined(__clang__)) && \
0522     !((defined(sun) || defined(__sun)) &&                                     \
0523       (defined(__SVR4) || defined(__svr4__)))
0524 #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 __attribute__((init_priority((101))))
0525 #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 __attribute__((init_priority((102))))
0526 #else
0527 #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY1
0528 #define PROTOBUF_ATTRIBUTE_INIT_PRIORITY2
0529 #endif
0530 
0531 #ifdef PROTOBUF_PRAGMA_INIT_SEG
0532 #error PROTOBUF_PRAGMA_INIT_SEG was previously defined
0533 #endif
0534 #ifdef _MSC_VER
0535 #define PROTOBUF_PRAGMA_INIT_SEG __pragma(init_seg(lib))
0536 #else
0537 #define PROTOBUF_PRAGMA_INIT_SEG
0538 #endif
0539 
0540 #ifdef PROTOBUF_ATTRIBUTE_WEAK
0541 #error PROTOBUF_ATTRIBUTE_WEAK was previously defined
0542 #endif
0543 #if ABSL_HAVE_ATTRIBUTE(weak) && !defined(__APPLE__) && \
0544     (!defined(_WIN32) || __clang_major__ < 9) && !defined(__MINGW32__)
0545 #define PROTOBUF_ATTRIBUTE_WEAK __attribute__((weak))
0546 #define PROTOBUF_HAVE_ATTRIBUTE_WEAK 1
0547 #else
0548 #define PROTOBUF_ATTRIBUTE_WEAK
0549 #define PROTOBUF_HAVE_ATTRIBUTE_WEAK 0
0550 #endif
0551 
0552 // Macros to detect sanitizers.
0553 #ifdef PROTOBUF_ASAN
0554 #error PROTOBUF_ASAN was previously defined
0555 #endif
0556 #ifdef PROTOBUF_MSAN
0557 #error PROTOBUF_MSAN was previously defined
0558 #endif
0559 #ifdef PROTOBUF_TSAN
0560 #error PROTOBUF_TSAN was previously defined
0561 #endif
0562 #if defined(__clang__)
0563 #if ABSL_HAVE_FEATURE(address_sanitizer)
0564 #    define PROTOBUF_ASAN 1
0565 #  endif
0566 #if ABSL_HAVE_FEATURE(thread_sanitizer)
0567 #    define PROTOBUF_TSAN 1
0568 #  endif
0569 #if ABSL_HAVE_FEATURE(memory_sanitizer)
0570 #    define PROTOBUF_MSAN 1
0571 #  endif
0572 #elif defined(__GNUC__)
0573 // Double-guard is needed for -Wundef:
0574 #  ifdef __SANITIZE_ADDRESS__
0575 #  if    __SANITIZE_ADDRESS__
0576 #    define PROTOBUF_ASAN 1
0577 #  endif
0578 #  endif
0579 #  ifdef __SANITIZE_THREAD__
0580 #  if    __SANITIZE_THREAD__
0581 #    define PROTOBUF_TSAN 1
0582 #  endif
0583 #  endif
0584 #  ifdef __SANITIZE_MEMORY__
0585 #  if    __SANITIZE_MEMORY__
0586 #    define PROTOBUF_ASAN 1
0587 #  endif
0588 #  endif
0589 #endif
0590 
0591 #ifdef PROTOBUF_ASAN
0592 #include <sanitizer/asan_interface.h>
0593 #define PROTOBUF_POISON_MEMORY_REGION(p, n) ASAN_POISON_MEMORY_REGION(p, n)
0594 #define PROTOBUF_UNPOISON_MEMORY_REGION(p, n) ASAN_UNPOISON_MEMORY_REGION(p, n)
0595 #else  // PROTOBUF_ASAN
0596 #define PROTOBUF_POISON_MEMORY_REGION(p, n)
0597 #define PROTOBUF_UNPOISON_MEMORY_REGION(p, n)
0598 #endif  // PROTOBUF_ASAN
0599 
0600 #ifdef PROTOBUF_TSAN
0601 #define PROTOBUF_TSAN_DECLARE_MEMBER ::uint32_t _tsan_detect_race = 0;
0602 #else
0603 #define PROTOBUF_TSAN_DECLARE_MEMBER
0604 #endif
0605 
0606 // Note that this is performance sensitive: changing the parameters will change
0607 // the registers used by the ABI calling convention, which subsequently affects
0608 // register selection logic inside the function.
0609 // Arguments `msg`, `ptr` and `ctx` are the 1st/2nd/3rd argument to match the
0610 // signature of ParseLoop.
0611 //
0612 // Note for x86_64: `data` must be the third or fourth argument for performance
0613 // reasons. In order to efficiently read the second byte of `data` we need it to
0614 // be passed in RDX or RCX.
0615 #define PROTOBUF_TC_PARAM_DECL                 \
0616   ::google::protobuf::MessageLite *msg, const char *ptr, \
0617       ::google::protobuf::internal::ParseContext *ctx,   \
0618       ::google::protobuf::internal::TcFieldData data,    \
0619       const ::google::protobuf::internal::TcParseTableBase *table, uint64_t hasbits
0620 // PROTOBUF_TC_PARAM_PASS passes values to match PROTOBUF_TC_PARAM_DECL.
0621 #define PROTOBUF_TC_PARAM_PASS msg, ptr, ctx, data, table, hasbits
0622 
0623 // PROTOBUF_TC_PARAM_NO_DATA_DECL and PROTOBUF_TC_PARAM_NO_DATA_PASS provide the
0624 // exact same ABI as above, except that they don't name or pass the `data`
0625 // argument. Specific functions such as `Error() and `ToTagDispatch()` don't
0626 // use the `data` argument. By not passing `data` down the call stack, we free
0627 // up the register holding that value, which may matter in highly optimized
0628 // functions such as varint parsing.
0629 #define PROTOBUF_TC_PARAM_NO_DATA_DECL                                        \
0630   ::google::protobuf::MessageLite *msg, const char *ptr,                                \
0631       ::google::protobuf::internal::ParseContext *ctx, ::google::protobuf::internal::TcFieldData, \
0632       const ::google::protobuf::internal::TcParseTableBase *table, uint64_t hasbits
0633 #define PROTOBUF_TC_PARAM_NO_DATA_PASS \
0634   msg, ptr, ctx, ::google::protobuf::internal::TcFieldData::DefaultInit(), table, hasbits
0635 
0636 #ifdef PROTOBUF_UNUSED
0637 #error PROTOBUF_UNUSED was previously defined
0638 #endif
0639 #if ABSL_HAVE_CPP_ATTRIBUTE(maybe_unused) || \
0640     (PROTOBUF_MSC_VER_MIN(1911) && PROTOBUF_CPLUSPLUS_MIN(201703L))
0641 #define PROTOBUF_UNUSED [[maybe_unused]]
0642 #elif ABSL_HAVE_ATTRIBUTE(unused) || defined(__GNUC__)
0643 #define PROTOBUF_UNUSED __attribute__((__unused__))
0644 #else
0645 #define PROTOBUF_UNUSED
0646 #endif
0647 
0648 // For the toolchains that support it, evalutes to `true` if the input is
0649 // determined to be a compile time constant after optimizations have happened
0650 // (like inlining and constant propagation). A `false` result means that the
0651 // compiler could not determine it is constant (it might still be but couldn't
0652 // figure it out).
0653 #ifdef PROTOBUF_BUILTIN_CONSTANT_P
0654 #error PROTOBUF_BUILTIN_CONSTANT_P was previously defined
0655 #endif
0656 #if ABSL_HAVE_BUILTIN(__builtin_constant_p)
0657 #define PROTOBUF_BUILTIN_CONSTANT_P(x) __builtin_constant_p(x)
0658 #else
0659 #define PROTOBUF_BUILTIN_CONSTANT_P(x) false
0660 #endif
0661 
0662 #ifdef PROTOBUF_CUSTOM_VTABLE
0663 #error PROTOBUF_CUSTOM_VTABLE was previously defined
0664 #endif
0665 #if !defined(PROTOBUF_CUSTOM_VTABLE)
0666 #define PROTOBUF_VIRTUAL virtual
0667 #define PROTOBUF_OVERRIDE override
0668 #define PROTOBUF_FINAL final
0669 #endif
0670 
0671 // Determines the platforms where descriptor weak messages can be used.
0672 #ifdef PROTOBUF_DESCRIPTOR_WEAK_MESSAGES_ALLOWED
0673 #error PROTOBUF_DESCRIPTOR_WEAK_MESSAGES_ALLOWED was previously defined
0674 #endif
0675 #if defined(__GNUC__) && defined(__clang__) && !defined(__APPLE__) && \
0676     !defined(_MSC_VER)
0677 #define PROTOBUF_DESCRIPTOR_WEAK_MESSAGES_ALLOWED
0678 #endif
0679 
0680 
0681 // TODO: Enable the feature by default and remove this flag.
0682 #ifdef PROTOBUF_PREFETCH_PARSE_TABLE
0683 #error PROTOBUF_PREFETCH_PARSE_TABLE was previously defined
0684 #endif
0685 
0686 #ifdef PROTOBUF_PREFETCH_WITH_OFFSET
0687 #error PROTOBUF_PREFETCH_WITH_OFFSET was previously defined
0688 #endif
0689 #if defined(__x86_64__) && defined(__GNUC__)
0690 #define PROTOBUF_PREFETCH_WITH_OFFSET(base, offset) \
0691   asm("prefetcht0 " #offset "(%0)" : : "r"(base));
0692 #else
0693 #define PROTOBUF_PREFETCH_WITH_OFFSET(base, offset)
0694 #endif
0695 
0696 // ThreadSafeArenaz is turned off completely in opensource builds.
0697 
0698 // noreturn is defined as a macro in C's stdnoreturn.h
0699 #ifdef noreturn
0700 #define PROTOBUF_DID_UNDEF_noreturn
0701 #pragma push_macro("noreturn")
0702 #undef noreturn
0703 #endif
0704 
0705 // autoheader defines this in some circumstances
0706 #ifdef PACKAGE
0707 #define PROTOBUF_DID_UNDEF_PACKAGE
0708 #pragma push_macro("PACKAGE")
0709 #undef PACKAGE
0710 #endif
0711 
0712 // a few common headers define this
0713 #ifdef PACKED
0714 #define PROTOBUF_DID_UNDEF_PACKED
0715 #pragma push_macro("PACKED")
0716 #undef PACKED
0717 #endif
0718 
0719 // This is a macro on Windows, macOS, and some variants of GCC.
0720 #ifdef DOMAIN
0721 #define PROTOBUF_DID_UNDEF_DOMAIN
0722 #pragma push_macro("DOMAIN")
0723 #undef DOMAIN
0724 #endif
0725 
0726 // linux is a legacy MACRO defined in most popular C++ standards.
0727 #ifdef linux
0728 #pragma push_macro("linux")
0729 #undef linux
0730 #define PROTOBUF_DID_UNDEF_LINUX
0731 #endif
0732 
0733 // Windows declares several inconvenient macro names.  We #undef them and then
0734 // restore them in port_undef.inc.
0735 #ifdef _WIN32
0736 #pragma push_macro("CompareString")
0737 #undef CompareString
0738 #pragma push_macro("CREATE_NEW")
0739 #undef CREATE_NEW
0740 #pragma push_macro("DELETE")
0741 #undef DELETE
0742 #pragma push_macro("DOUBLE_CLICK")
0743 #undef DOUBLE_CLICK
0744 #pragma push_macro("ERROR")
0745 #undef ERROR
0746 #pragma push_macro("ERROR_BUSY")
0747 #undef ERROR_BUSY
0748 #pragma push_macro("ERROR_INSTALL_FAILED")
0749 #undef ERROR_INSTALL_FAILED
0750 #pragma push_macro("ERROR_NOT_FOUND")
0751 #undef ERROR_NOT_FOUND
0752 #pragma push_macro("ERROR_RETRY")
0753 #undef ERROR_RETRY
0754 #pragma push_macro("ERROR_TIMEOUT")
0755 #undef ERROR_TIMEOUT
0756 #pragma push_macro("GetClassName")
0757 #undef GetClassName
0758 #pragma push_macro("GetCurrentTime")
0759 #undef GetCurrentTime
0760 #pragma push_macro("GetMessage")
0761 #undef GetMessage
0762 #pragma push_macro("GetObject")
0763 #undef GetObject
0764 #pragma push_macro("IGNORE")
0765 #undef IGNORE
0766 #pragma push_macro("IN")
0767 #undef IN
0768 #pragma push_macro("INPUT_KEYBOARD")
0769 #undef INPUT_KEYBOARD
0770 #pragma push_macro("NO_ERROR")
0771 #undef NO_ERROR
0772 #pragma push_macro("OUT")
0773 #undef OUT
0774 #pragma push_macro("OPTIONAL")
0775 #undef OPTIONAL
0776 #pragma push_macro("min")
0777 #undef min
0778 #pragma push_macro("max")
0779 #undef max
0780 #pragma push_macro("NEAR")
0781 #undef NEAR
0782 #pragma push_macro("NO_DATA")
0783 #undef NO_DATA
0784 #pragma push_macro("REASON_UNKNOWN")
0785 #undef REASON_UNKNOWN
0786 #pragma push_macro("SERVICE_DISABLED")
0787 #undef SERVICE_DISABLED
0788 #pragma push_macro("SERVICE_STOP")
0789 #undef SERVICE_STOP
0790 #pragma push_macro("SEVERITY_ERROR")
0791 #undef SEVERITY_ERROR
0792 #pragma push_macro("STATUS_PENDING")
0793 #undef STATUS_PENDING
0794 #pragma push_macro("STRICT")
0795 #undef STRICT
0796 #pragma push_macro("timezone")
0797 #undef timezone
0798 #pragma push_macro("TRUE")
0799 #undef TRUE
0800 #pragma push_macro("FALSE")
0801 #undef FALSE
0802 #endif  // _WIN32
0803 
0804 #ifdef __APPLE__
0805 // Inconvenient macro names from /usr/include/mach/boolean.h in some macOS SDKs.
0806 #pragma push_macro("TRUE")
0807 #undef TRUE
0808 #pragma push_macro("FALSE")
0809 #undef FALSE
0810 // Inconvenient macro names from usr/include/sys/syslimits.h in some macOS SDKs.
0811 #pragma push_macro("UID_MAX")
0812 #undef UID_MAX
0813 #pragma push_macro("GID_MAX")
0814 #undef GID_MAX
0815 // TYPE_BOOL is defined in the MacOS's ConditionalMacros.h.
0816 #pragma push_macro("TYPE_BOOL")
0817 #undef TYPE_BOOL
0818 #endif  // __APPLE__
0819 
0820 #if defined(ANDROID) || defined(__ANDROID__)
0821 // Inconvenient macro names from usr/include/limits.h in some Android NDKs.
0822 #pragma push_macro("UID_MAX")
0823 #undef UID_MAX
0824 #pragma push_macro("GID_MAX")
0825 #undef GID_MAX
0826 #endif  // defined(ANDROID) || defined(__ANDROID__)
0827 
0828 #ifdef __FreeBSD__
0829 // Inconvenient macro names from /usr/include/sys/param.h.
0830 #pragma push_macro("TRUE")
0831 #undef TRUE
0832 #pragma push_macro("FALSE")
0833 #undef FALSE
0834 // Inconvenient macro names from /usr/include/sys/limits.h.
0835 #pragma push_macro("UID_MAX")
0836 #undef UID_MAX
0837 #pragma push_macro("GID_MAX")
0838 #undef GID_MAX
0839 #endif  // __FreeBSD__
0840 
0841 #if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
0842 // Don't let Objective-C Macros interfere with proto identifiers with the same
0843 // name.
0844 #pragma push_macro("DEBUG")
0845 #undef DEBUG
0846 #endif // defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
0847 
0848 // Protobuf does not support building with a number of warnings that are noisy
0849 // (and of variable quality across compiler versions) or impossible to implement
0850 // effectively but which people turn on anyways.
0851 #ifdef __clang__
0852 #pragma clang diagnostic push
0853 // -Wshorten-64-to-32 is a typical pain where we diff pointers.
0854 //   char* p = strchr(s, '\n');
0855 //   return p ? p - s : -1;
0856 #pragma clang diagnostic ignored "-Wshorten-64-to-32"
0857 // Turn on -Wdeprecated-enum-enum-conversion. This deprecation comes in C++20
0858 // via http://wg21.link/p1120r0.
0859 #pragma clang diagnostic error "-Wdeprecated-enum-enum-conversion"
0860 // This error has been generally flaky, but we need to disable it specifically
0861 // to fix https://github.com/protocolbuffers/protobuf/issues/12313
0862 #pragma clang diagnostic ignored "-Wunused-parameter"
0863 // -Wshadow means that declaration shadows a variable.
0864 // for (int i = 0; i < file_->public_dependency_count(); ++i)
0865 //   for (int i = 0; i < public_dep->message_type_count(); ++i)
0866 #pragma clang diagnostic ignored "-Wshadow"
0867 #pragma clang diagnostic ignored "-Wextra-semi"
0868 #endif
0869 #ifdef __GNUC__
0870 #pragma GCC diagnostic push
0871 // Some of the warnings below only exist in some GCC versions; those version
0872 // ranges are poorly documented.
0873 #pragma GCC diagnostic ignored "-Wpragmas"
0874 // GCC does not allow disabling diagnostics within an expression:
0875 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, so we disable this one
0876 // globally even though it's only used for PROTOBUF_FIELD_OFFSET.
0877 #pragma GCC diagnostic ignored "-Winvalid-offsetof"
0878 // Some versions of GCC seem to think that
0879 //  [this] { Foo(); }
0880 // leaves `this` unused, even though `Foo();` is a member function of the
0881 // captured `this`.
0882 // https://bugzilla.mozilla.org/show_bug.cgi?id=1373625
0883 #pragma GCC diagnostic ignored "-Wunused-lambda-capture"
0884 // -Wsign-conversion causes a lot of warnings on mostly code like:
0885 //   int index = ...
0886 //   int value = vec[index];
0887 #pragma GCC diagnostic ignored "-Wsign-conversion"
0888 // This error has been generally flaky, but we need to disable it specifically
0889 // to fix https://github.com/protocolbuffers/protobuf/issues/12313
0890 #pragma GCC diagnostic ignored "-Wunused-parameter"
0891 // -Wshadow means that declaration shadows a variable.
0892 // for (int i = 0; i < file_->public_dependency_count(); ++i)
0893 //   for (int i = 0; i < public_dep->message_type_count(); ++i)
0894 #pragma GCC diagnostic ignored "-Wshadow"
0895 #ifndef __clang__
0896 // This causes spurious warnings in GCC 13.
0897 #pragma GCC diagnostic ignored "-Wstringop-overflow"
0898 // This causes spurious warnings in GCC 13.
0899 #pragma GCC diagnostic ignored "-Wself-move"
0900 // Ignore warning: extra ';' [-Wpedantic]
0901 #pragma GCC diagnostic ignored "-Wpedantic"
0902 #endif
0903 #if __GNUC__ == 12 && __GNUC_MINOR__ < 4
0904 // Wrong warning emitted when assigning a single char c-string to a std::string
0905 // in c++20 mode and optimization on.
0906 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329
0907 // Planned to be fixed by 12.3 but widen window to 12.4.
0908 #pragma GCC diagnostic ignored "-Wrestrict"
0909 #endif
0910 #endif  // __GNUC__
0911 
0912 // Silence some MSVC warnings in all our code.
0913 #ifdef _MSC_VER
0914 #pragma warning(push)
0915 // For non-trivial unions
0916 #pragma warning(disable : 4582)
0917 #pragma warning(disable : 4583)
0918 // For init_seg(lib)
0919 #pragma warning(disable : 4073)
0920 // To silence the fact that we will pop this push from another file
0921 #pragma warning(disable : 5031)
0922 // Conditional expression is constant
0923 #pragma warning(disable: 4127)
0924 // decimal digit terminates octal escape sequence
0925 #pragma warning(disable: 4125)
0926 #endif
0927 
0928 #if PROTOBUF_ENABLE_DEBUG_LOGGING_MAY_LEAK_PII
0929 #define PROTOBUF_DEBUG true
0930 #else
0931 #define PROTOBUF_DEBUG false
0932 #endif
0933 
0934 #ifdef PROTOBUF_NO_THREADLOCAL
0935 #error PROTOBUF_NO_THREADLOCAL was previously defined
0936 #endif
0937 
0938 // port_def.inc may be included in very large compilation targets, so we need to
0939 // minimize adding symbol and source file information here. For this reason we
0940 // implement our own simple `protobuf_assumption_failed()` function for
0941 // asserting PROTOBUF_ASSUME predicates in debug builds.
0942 namespace google {
0943 namespace protobuf {
0944 namespace internal {
0945 [[noreturn]] PROTOBUF_EXPORT void protobuf_assumption_failed(const char *pred,
0946                                                              const char *file,
0947                                                              int line);
0948 }  // namespace internal
0949 }  // namespace protobuf
0950 }  // namespace google
0951 
0952 // PROTOBUF_ASSUME(pred) tells the compiler that it can assume pred is true.
0953 // To be safe, we also validate the assumption in debug builds, printing an
0954 // assert style "Assumption failed: ..." message and aborting the program if
0955 // the predicate is false. The macro does not do anything useful if the
0956 // compiler does not support __builtin_assume.
0957 #ifdef PROTOBUF_ASSUME
0958 #error PROTOBUF_ASSUME was previously defined
0959 #endif
0960 #if ABSL_HAVE_BUILTIN(__builtin_assume)
0961 #ifdef NDEBUG
0962 #define PROTOBUF_ASSUME(pred) __builtin_assume(pred)
0963 #else  // NDEBUG
0964 #define PROTOBUF_ASSUME(pred)                                                  \
0965   if (!(pred)) {                                                               \
0966     ::google::protobuf::internal::protobuf_assumption_failed(#pred, __FILE__, __LINE__); \
0967   }                                                                            \
0968   __builtin_assume(pred)
0969 #endif  // NDEBUG
0970 #else   // has_builtin(__builtin_assume)
0971 #ifndef NDEBUG
0972 #define PROTOBUF_ASSUME(pred)                                                  \
0973   if (!(pred)) {                                                               \
0974     ::google::protobuf::internal::protobuf_assumption_failed(#pred, __FILE__, __LINE__); \
0975   }
0976 #else  // !NDEBUG
0977 #define PROTOBUF_ASSUME(pred)
0978 #endif  // !NDEBUG
0979 #endif  // has_builtin(__builtin_assume)
0980 
0981 #ifdef PROTOBUF_DEPRECATE_AND_INLINE
0982 #error PROTOBUF_DEPRECATE_AND_INLINE was previously defined
0983 #endif
0984 #if defined(ABSL_DEPRECATE_AND_INLINE)
0985 #define PROTOBUF_DEPRECATE_AND_INLINE() ABSL_DEPRECATE_AND_INLINE()
0986 #else
0987 #define PROTOBUF_DEPRECATE_AND_INLINE() [[deprecated]]
0988 #endif
0989 
0990 
0991 namespace google {
0992 namespace protobuf {
0993 namespace internal {
0994 #if defined(PROTOBUF_INTERNAL_ENABLE_DEBUG_COUNTERS)
0995 #define PROTOBUF_DEBUG_COUNTER(name)                                   \
0996   ([]() -> auto & {                                                    \
0997     static constexpr const char *counter_name = name;                  \
0998     static ::google::protobuf::internal::RealDebugCounter counter(counter_name); \
0999     return counter;                                                    \
1000   }())
1001 
1002 #else  // PROTOBUF_ENABLE_DEBUG_COUNTERS
1003 #define PROTOBUF_DEBUG_COUNTER(name) \
1004   ::google::protobuf::internal::NoopDebugCounter {}
1005 #endif  // PROTOBUF_ENABLE_DEBUG_COUNTERS
1006 }  // namespace internal
1007 }  // namespace protobuf
1008 }  // namespace google