Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
compiler_specific.h
Go to the documentation of this file.
1// Copyright 2024 The PDFium 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 CORE_FXCRT_COMPILER_SPECIFIC_H_
6#define CORE_FXCRT_COMPILER_SPECIFIC_H_
7
8#include "build/build_config.h"
9
10// A wrapper around `__has_attribute`, similar to HAS_CPP_ATTRIBUTE.
11#if defined(__has_attribute)
12#define HAS_ATTRIBUTE(x) __has_attribute(x)
13#else
14#define HAS_ATTRIBUTE(x) 0
15#endif
16
17// Annotate a function indicating it should not be inlined.
18// Use like:
19// NOINLINE void DoStuff() { ... }
20#if defined(__clang__) && HAS_ATTRIBUTE(noinline)
21#define NOINLINE [[clang::noinline]]
22#elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(noinline)
23#define NOINLINE __attribute__((noinline))
24#elif defined(COMPILER_MSVC)
25#define NOINLINE __declspec(noinline)
26#else
27#define NOINLINE
28#endif
29
30// Macro for hinting that an expression is likely to be false.
31#if !defined(UNLIKELY)
32#if defined(COMPILER_GCC) || defined(__clang__)
33#define UNLIKELY(x) __builtin_expect(!!(x), 0)
34#else
35#define UNLIKELY(x) (x)
36#endif // defined(COMPILER_GCC)
37#endif // !defined(UNLIKELY)
38
39#if !defined(LIKELY)
40#if defined(COMPILER_GCC) || defined(__clang__)
41#define LIKELY(x) __builtin_expect(!!(x), 1)
42#else
43#define LIKELY(x) (x)
44#endif // defined(COMPILER_GCC)
45#endif // !defined(LIKELY)
46
47// Marks a type as being eligible for the "trivial" ABI despite having a
48// non-trivial destructor or copy/move constructor. Such types can be relocated
49// after construction by simply copying their memory, which makes them eligible
50// to be passed in registers. The canonical example is std::unique_ptr.
51//
52// Use with caution; this has some subtle effects on constructor/destructor
53// ordering and will be very incorrect if the type relies on its address
54// remaining constant. When used as a function argument (by value), the value
55// may be constructed in the caller's stack frame, passed in a register, and
56// then used and destructed in the callee's stack frame. A similar thing can
57// occur when values are returned.
58//
59// TRIVIAL_ABI is not needed for types which have a trivial destructor and
60// copy/move constructors, such as base::TimeTicks and other POD.
61//
62// It is also not likely to be effective on types too large to be passed in one
63// or two registers on typical target ABIs.
64//
65// See also:
66// https://clang.llvm.org/docs/AttributeReference.html#trivial-abi
67// https://libcxx.llvm.org/docs/DesignDocs/UniquePtrTrivialAbi.html
68#if defined(__clang__) && HAS_ATTRIBUTE(trivial_abi)
69#define TRIVIAL_ABI [[clang::trivial_abi]]
70#else
71#define TRIVIAL_ABI
72#endif
73
74#if defined(__clang__)
75#define GSL_POINTER [[gsl::Pointer]]
76#else
77#define GSL_POINTER
78#endif
79
80#if defined(__clang__) && HAS_ATTRIBUTE(unsafe_buffer_usage)
81#define UNSAFE_BUFFER_USAGE [[clang::unsafe_buffer_usage]]
82#else
83#define UNSAFE_BUFFER_USAGE
84#endif
85
86// clang-format off
87// Formatting is off so that we can put each _Pragma on its own line, as
88// recommended by the gcc docs.
89#if defined(PDF_USE_CHROME_PLUGINS)
90#define UNSAFE_BUFFERS(...)
91 _Pragma("clang unsafe_buffer_usage begin")
92 __VA_ARGS__
93 _Pragma("clang unsafe_buffer_usage end")
94#else
95#define UNSAFE_BUFFERS(...) __VA_ARGS__
96#endif
97// clang-format on
98
99// Like UNSAFE_BUFFERS(), but indicates there is a TODO() task to
100// investigate safety,
101// TODO(crbug.com/pdfium/2155): remove all usage.
102#define UNSAFE_TODO(...) UNSAFE_BUFFERS(__VA_ARGS__)
103
104#endif // CORE_FXCRT_COMPILER_SPECIFIC_H_
T & reference
Definition span.h:195
constexpr span(T(&array)[N]) noexcept
Definition span.h:211
constexpr reverse_iterator rend() const noexcept
Definition span.h:348
span last() const
Definition span.h:283
constexpr reverse_iterator rbegin() const noexcept
Definition span.h:345
T * iterator
Definition span.h:196
constexpr const_reverse_iterator crend() const noexcept
Definition span.h:355
span first() const
Definition span.h:269
std::reverse_iterator< iterator > reverse_iterator
Definition span.h:198
const span first(size_t count) const
Definition span.h:276
typename std::remove_cv< T >::type value_type
Definition span.h:193
span & operator=(const span &other) noexcept
Definition span.h:258
constexpr const_iterator cbegin() const noexcept
Definition span.h:342
constexpr const_iterator cend() const noexcept
Definition span.h:343
constexpr const_reverse_iterator crbegin() const noexcept
Definition span.h:352
const span last(size_t count) const
Definition span.h:290
constexpr bool empty() const noexcept
Definition span.h:316
constexpr size_t size() const noexcept
Definition span.h:314
constexpr span(Container &container)
Definition span.h:238
friend constexpr span< U > make_span(U *data, size_t size) noexcept
span subspan() const
Definition span.h:297
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition span.h:199
const span subspan(size_t pos, size_t count=dynamic_extent) const
Definition span.h:305
constexpr iterator begin() const noexcept
Definition span.h:337
constexpr size_t size_bytes() const noexcept
Definition span.h:315
constexpr span() noexcept=default
span(const Container &container)
Definition span.h:245
constexpr span(std::array< T, N > &array) noexcept
Definition span.h:216
T * pointer
Definition span.h:194
constexpr T & back() const noexcept
Definition span.h:329
constexpr span(const std::array< std::remove_cv_t< T >, N > &array) noexcept
Definition span.h:221
constexpr T * data() const noexcept
Definition span.h:334
constexpr T & front() const noexcept
Definition span.h:324
constexpr span(const span &other) noexcept=default
UNSAFE_BUFFER_USAGE constexpr span(T *data, size_t size) noexcept
Definition span.h:204
constexpr span(const span< U, M, R > &other)
Definition span.h:255
T & operator[](size_t index) const noexcept
Definition span.h:319
constexpr iterator end() const noexcept
Definition span.h:338
const T * const_iterator
Definition span.h:197
~span() noexcept=default
#define UNSAFE_BUFFERS(...)
#define GSL_POINTER
#define TRIVIAL_ABI
#define UNLIKELY(x)
#define HAS_ATTRIBUTE(x)
#define UNSAFE_BUFFER_USAGE
void CRYPT_MD5Finish(CRYPT_md5_context *context, pdfium::span< uint8_t, 16 > digest)
Definition fx_crypt.cpp:203
#define P(a, b, c, d, k, s, t)
void CRYPT_MD5Generate(pdfium::span< const uint8_t > data, pdfium::span< uint8_t, 16 > digest)
Definition fx_crypt.cpp:219
#define S(x, n)
void CRYPT_ArcFourCryptBlock(pdfium::span< uint8_t > data, pdfium::span< const uint8_t > key)
Definition fx_crypt.cpp:157
void CRYPT_ArcFourSetup(CRYPT_rc4_context *context, pdfium::span< const uint8_t > key)
Definition fx_crypt.cpp:131
void CRYPT_MD5Update(CRYPT_md5_context *context, pdfium::span< const uint8_t > data)
Definition fx_crypt.cpp:175
void CRYPT_ArcFourCrypt(CRYPT_rc4_context *context, pdfium::span< uint8_t > data)
Definition fx_crypt.cpp:146
CRYPT_md5_context CRYPT_MD5Start()
Definition fx_crypt.cpp:164
void CRYPT_AESEncrypt(CRYPT_aes_context *ctx, pdfium::span< uint8_t > dest, pdfium::span< const uint8_t > src)
void CRYPT_AESSetIV(CRYPT_aes_context *ctx, const uint8_t *iv)
void CRYPT_AESDecrypt(CRYPT_aes_context *ctx, uint8_t *dest, const uint8_t *src, uint32_t size)
void CRYPT_AESSetKey(CRYPT_aes_context *ctx, const uint8_t *key, uint32_t keylen)
std::is_integral< decltype(std::declval< Container >().size())> ContainerHasIntegralSize
Definition span.h:63
IsSpanImpl< typename std::decay< T >::type > IsSpan
Definition span.h:43
std::is_convertible< From *, To * > IsLegalSpanConversion
Definition span.h:55
IsStdArrayImpl< typename std::decay< T >::type > IsStdArray
Definition span.h:52
constexpr span< T > make_span(T(&array)[N]) noexcept
Definition span.h:374
span< char > as_writable_chars(span< T, N, P > s) noexcept
Definition span.h:427
span< const uint8_t > as_bytes(span< T, N, P > s) noexcept
Definition span.h:400
constexpr size_t dynamic_extent
Definition span.h:24
static constexpr span< T > span_from_ref(T &single_object) noexcept
Definition span.h:437
static constexpr span< const uint8_t > byte_span_from_ref(const T &single_object) noexcept
Definition span.h:446
UNSAFE_BUFFER_USAGE constexpr span< T > make_span(T *data, size_t size) noexcept
Definition span.h:369
span< const uint8_t > as_byte_span(T &&arg)
Definition span.h:465
span< const char > as_chars(span< T, N, P > s) noexcept
Definition span.h:417
span< const uint8_t > as_byte_span(const T &arg)
Definition span.h:461
UNOWNED_PTR_EXCLUSION T * DefaultSpanInternalPtr
Definition span.h:27
span< uint8_t > as_writable_bytes(span< T, N, P > s) noexcept
Definition span.h:410
constexpr span< T > make_span(std::array< T, N > &array) noexcept
Definition span.h:379
constexpr span< T > make_span(Container &container)
Definition span.h:386
constexpr span< uint8_t > as_writable_byte_span(T &&arg)
Definition span.h:475
static constexpr span< uint8_t > byte_span_from_ref(T &single_object) noexcept
Definition span.h:451
constexpr span< T > make_span(const Container &container)
Definition span.h:394
#define CHECK(cvref)
#define assert
#define __has_attribute(x)
std::array< uint32_t, kMaxNb > iv
std::array< uint32_t, kSchedSize > invkeysched
static constexpr int kMaxNr
static constexpr int kSchedSize
static constexpr int kMaxNb
std::array< uint32_t, kSchedSize > keysched
uint8_t buffer[64]
Definition fx_crypt.h:28
std::array< uint32_t, 4 > state
Definition fx_crypt.h:27
std::array< uint32_t, 2 > total
Definition fx_crypt.h:26
std::array< int32_t, kPermutationLength > m
Definition fx_crypt.h:22
static constexpr int32_t kPermutationLength
Definition fx_crypt.h:18
#define UNOWNED_PTR_EXCLUSION