UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ClangPlatform.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*================================================================================
4 ClangPlatform.h: Setup for any Clang-using platform
5==================================================================================*/
6
7#pragma once
8
9// HEADER_UNIT_UNSUPPORTED - Clang not supporting header units
10
11#if defined(__clang__)
12
13#if !defined(__cpp_if_constexpr)
14 #error "Compiler is expected to support if constexpr"
15#endif
16
17#if !defined(__cpp_fold_expressions)
18 #error "Compiler is expected to support fold expressions"
19#endif
20
21#if !__has_feature(cxx_decltype_auto)
22 #error "Compiler is expected to support decltype(auto)"
23#endif
24
25#define PLATFORM_RETURN_ADDRESS() __builtin_return_address(0)
26#define PLATFORM_RETURN_ADDRESS_POINTER() __builtin_frame_address(0)
27
28#define UE_LIFETIMEBOUND [[clang::lifetimebound]]
29
30#define UE_NODEBUG [[gnu::nodebug]]
31
32// Clang supports the following GNU attributes to let us describe allocation functions.
33// `gnu::malloc` maps to the `noalias` function return on the caller in the LLVM IR.
34// `gnu::alloc_size` maps to the `allocsize` function attribute on the caller in the LLVM IR.
35// `gnu::alloc_align` will cause any memory operations in the callee to have the specified alignment in the LLVM IR.
36// We use a selector macro trick to map up to 2 inputs to the correct macros.
37#define UE_ALLOCATION_FUNCTION_0() [[gnu::malloc]]
38#define UE_ALLOCATION_FUNCTION_1(SIZE) [[gnu::malloc, gnu::alloc_size(SIZE)]]
39
40// Note: we cannot use gnu::alloc_align(ALIGN) here yet, because the DEFAULT_ALIGNMENT argument is 0, which is not
41// a power of two, and Clang will complain about uses of a function with a default alignment that is not a
42// power of two.
43#define UE_ALLOCATION_FUNCTION_2(SIZE, ALIGN) [[gnu::malloc, gnu::alloc_size(SIZE)]]
44#define UE_ALLOCATION_FUNCTION_X(x, SIZE, ALIGN, FUNC, ...) FUNC
45#define UE_ALLOCATION_FUNCTION(...) UE_ALLOCATION_FUNCTION_X(,##__VA_ARGS__, UE_ALLOCATION_FUNCTION_2(__VA_ARGS__), UE_ALLOCATION_FUNCTION_1(__VA_ARGS__), UE_ALLOCATION_FUNCTION_0(__VA_ARGS__))
46
47// Ensure we can use this builtin - seems to be present on Clang 9, GCC 11 and MSVC 19.26,
48#define PLATFORM_COMPILER_SUPPORTS_BUILTIN_BITCAST (__clang_major__ >= 9)
49
50#define FUNCTION_NON_NULL_RETURN_START [[gnu::returns_nonnull]]
51
52#if defined(__has_attribute)
53# if __has_attribute(no_profile_instrument_function)
54# define UE_NO_PROFILE_ATTRIBUTE __attribute__((no_profile_instrument_function))
55# endif
56#endif
57
58#ifndef UE_NO_PROFILE_ATTRIBUTE
59# define UE_NO_PROFILE_ATTRIBUTE
60#endif
61
62#define CALLSITE_FORCEINLINE [[clang::always_inline]] /* Force code to be inlined at the callsite */
63
64#endif//defined(__clang__)