UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AutoRTFMDefines.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// IWYU pragma: private
4// Include include "AutoRTFM.h" instead
5
6#pragma once
7
8#if (defined(__AUTORTFM) && __AUTORTFM)
9#define UE_AUTORTFM 1 // Compiler is 'verse-clang'
10#else
11#define UE_AUTORTFM 0
12#endif
13
14#if (defined(__AUTORTFM_ENABLED) && __AUTORTFM_ENABLED)
15#define UE_AUTORTFM_ENABLED 1 // Compiled with '-fautortfm'
16#else
17#define UE_AUTORTFM_ENABLED 0
18#endif
19
20#if !defined(UE_AUTORTFM_ENABLED_RUNTIME_BY_DEFAULT)
21#define UE_AUTORTFM_ENABLED_RUNTIME_BY_DEFAULT 1
22#endif
23
24#if !defined(UE_AUTORTFM_STATIC_VERIFIER)
25#define UE_AUTORTFM_STATIC_VERIFIER 0
26#endif
27
28#if UE_AUTORTFM
29// The annotated function will have no AutoRTFM closed variant generated, and
30// cannot be called from another closed function. This attribute will eventually
31// be deprecated and replaced with AUTORTFM_DISABLE.
32#define UE_AUTORTFM_NOAUTORTFM [[clang::noautortfm]]
33
34// Omits AutoRTFM instrumentation from the function. Calling this annotated
35// function from the closed will automatically enter the open for the duration
36// of the call and will return back to the closed.
37#define UE_AUTORTFM_ALWAYS_OPEN [[clang::autortfm_always_open]]
38
39// The same as UE_AUTORTFM_ALWAYS_OPEN, but disables memory validation for this
40// call.
41#define UE_AUTORTFM_ALWAYS_OPEN_NO_MEMORY_VALIDATION [[clang::autortfm_always_open_disable_memory_validation]]
42
43// Annotation that can be applied to classes, methods or functions to prevent
44// AutoRTFM closed function(s) from being generated.
45// Applying the annotation to a class is equivalent to applying the annotation
46// to each method of the class.
47// When annotating a function, the attribute must be placed on a the function
48// declaration (usually in the header) and not a function implementation.
49// Annotated functions cannot be called from another closed function and
50// attempting to do so will result in a runtime failure.
51#define AUTORTFM_DISABLE [[clang::autortfm(disable)]]
52
53// Applies the AUTORTFM_DISABLE annotation if the condition argument evaluates to true.
54// Warning: This is an experimental API and may be removed in the future.
55#define AUTORTFM_DISABLE_IF(...) [[clang::autortfm(disable, __VA_ARGS__)]]
56
57// Begins a range where all classes and functions will be automatically
58// annotated with AUTORTFM_DISABLE. Must be ended with AUTORTFM_DISABLE_END
59// before the end of the file.
60#define AUTORTFM_DISABLE_BEGIN _Pragma("clang attribute AutoRTFM_Disable.push (AUTORTFM_DISABLE, apply_to = any(function, record))")
61
62// Ends a range started with AUTORTFM_DISABLE_BEGIN
63#define AUTORTFM_DISABLE_END _Pragma("clang attribute AutoRTFM_Disable.pop")
64
65// Annotation that can be applied to classes, methods or functions to re-enable
66// AutoRTFM instrumentation which would otherwise be disabled by AUTORTFM_DISABLE.
67// Useful for selectively enabling AutoRTFM on methods when a class is annotated
68// AUTORTFM_DISABLE.
69#define AUTORTFM_ENABLE [[clang::autortfm(enable)]]
70
71// Annotation that can be applied to classes, methods or functions to infer
72// whether AutoRTFM instrumentation should be enabled for each individual
73// function based on the AutoRTFM-enabled state of each callee made by the
74// function. If the function calls any AutoRTFM-disabled function, then the
75// function will also be AutoRTFM-disabled, otherwise the function is
76// AutoRTFM-enabled.
77// Applying the annotation to a class is equivalent to applying the annotation
78// to each method of the class.
79// When annotating a function, the attribute must be placed on a the function
80// declaration (usually in the header) and not a function implementation.
81#define AUTORTFM_INFER [[clang::autortfm(infer)]]
82
83// Annotation that can be applied to classes, methods or functions to prevent
84// AutoRTFM closed function(s) from being generated. Unlike AUTORTFM_DISABLE
85// annotated functions can be called from closed functions, which will call
86// the uninstrumented function.
87// Applying the annotation to a class is equivalent to applying the annotation
88// to each method of the class.
89// When annotating a function, the attribute must be placed on a the function
90// declaration (usually in the header) and not a function implementation.
91#define AUTORTFM_OPEN [[clang::autortfm(open)]]
92
93// Similar to AUTORTFM_OPEN, but disables memory validation on the call.
94#define AUTORTFM_OPEN_NO_VALIDATION [[clang::autortfm(open_no_validation)]]
95
96// Evaluates to a constant true if:
97// * EXPR_OR_TYPE is an address of a AutoRTFM-disabled function or method
98// * EXPR_OR_TYPE is a type of a AutoRTFM-disabled class or struct
99// Warning: This is an experimental API and may be removed in the future.
100#define AUTORTFM_IS_DISABLED(EXPR_OR_TYPE) __autortfm_is_disabled(EXPR_OR_TYPE)
101
102// Evaluates to a constant true if CALL_EXPR is a call a function, method,
103// constructor (new T(...)) or destructor, and the call target is
104// AutoRTFM-disabled.
105// Warning: This is an experimental API and may be removed in the future.
106#define AUTORTFM_CALL_IS_DISABLED(CALL_EXPR) __autortfm_is_disabled(__autortfm_declcall(CALL_EXPR))
107
108// Force the call statement to be inlined.
109#define UE_AUTORTFM_CALLSITE_FORCEINLINE [[clang::always_inline]]
110
111#else // ^^^ UE_AUTORTFM ^^^ | vvv !UE_AUTORTFM vvv
112
113#define UE_AUTORTFM_NOAUTORTFM
114#define UE_AUTORTFM_ALWAYS_OPEN
115#define UE_AUTORTFM_ALWAYS_OPEN_NO_MEMORY_VALIDATION
116#define AUTORTFM_DISABLE
117#define AUTORTFM_DISABLE_IF(CONDITION)
118#define AUTORTFM_DISABLE_BEGIN
119#define AUTORTFM_DISABLE_END
120#define AUTORTFM_ENABLE
121#define AUTORTFM_INFER
122#define AUTORTFM_OPEN
123#define AUTORTFM_OPEN_NO_VALIDATION
124#define AUTORTFM_IS_DISABLED(EXPR_OR_TYPE) false
125#define AUTORTFM_CALL_IS_DISABLED(EXPR_OR_TYPE) false
126#define UE_AUTORTFM_CALLSITE_FORCEINLINE
127
128#endif
129
130#ifdef __cplusplus
131#define AUTORTFM_NOEXCEPT noexcept
132#define AUTORTFM_EXCEPT noexcept(false)
133#else
134#define AUTORTFM_NOEXCEPT
135#define AUTORTFM_EXCEPT
136#endif
137
138#if UE_AUTORTFM && UE_AUTORTFM_STATIC_VERIFIER
139#define UE_AUTORTFM_ENSURE_SAFE [[clang::autortfm_ensure_safe]]
140#define UE_AUTORTFM_ASSUME_SAFE [[clang::autortfm_assume_safe]]
141#else
142#define UE_AUTORTFM_ENSURE_SAFE
143#define UE_AUTORTFM_ASSUME_SAFE
144#endif
145
146#define UE_AUTORTFM_CONCAT_IMPL(A, B) A ## B
147#define UE_AUTORTFM_CONCAT(A, B) UE_AUTORTFM_CONCAT_IMPL(A, B)
148
149#if defined(__cplusplus) && defined(__UNREAL__) && !(defined(UE_AUTORTFM_DO_NOT_INCLUDE_PLATFORM_H) && UE_AUTORTFM_DO_NOT_INCLUDE_PLATFORM_H)
150 // Include HAL/Platform.h for DLLIMPORT / DLLEXPORT definitions, which
151 // UBT can use as a definition for AUTORTFM_API.
152 #include <HAL/Platform.h>
153 #define UE_AUTORTFM_API AUTORTFM_API
154#else
155 #ifndef UE_AUTORTFM_API
156 #define UE_AUTORTFM_API
157 #endif
158#endif
159
160#if defined(_MSC_VER)
161#define UE_AUTORTFM_FORCEINLINE __forceinline
162#define UE_AUTORTFM_FORCEINLINE_ALWAYS __forceinline
163#define UE_AUTORTFM_FORCENOINLINE __declspec(noinline)
164#define UE_AUTORTFM_ASSUME(x) __assume(x)
165#elif defined(__clang__)
166#define UE_AUTORTFM_FORCEINLINE __attribute__((always_inline)) inline
167#define UE_AUTORTFM_FORCEINLINE_ALWAYS __attribute__((always_inline)) inline
168#define UE_AUTORTFM_FORCENOINLINE __attribute__((noinline))
169#define UE_AUTORTFM_ASSUME(x) __builtin_assume(x)
170#else
171#define UE_AUTORTFM_FORCEINLINE inline
172#define UE_AUTORTFM_FORCEINLINE_ALWAYS inline
173#define UE_AUTORTFM_FORCENOINLINE
174#define UE_AUTORTFM_ASSUME(x)
175#endif
176
177
178#if (defined(UE_BUILD_DEBUG) && UE_BUILD_DEBUG) || (defined(AUTORTFM_BUILD_DEBUG) && AUTORTFM_BUILD_DEBUG)
179// Force-inlining can make debugging glitchy. Disable this if we're running a debug build.
180#undef UE_AUTORTFM_CALLSITE_FORCEINLINE
181#define UE_AUTORTFM_CALLSITE_FORCEINLINE
182#undef UE_AUTORTFM_FORCEINLINE
183#define UE_AUTORTFM_FORCEINLINE inline
184#endif
185
186#ifdef _MSC_VER
187#define AUTORTFM_DISABLE_UNREACHABLE_CODE_WARNINGS \
188 __pragma (warning(push)) \
189 __pragma (warning(disable: 4702)) /* unreachable code */
190#define AUTORTFM_RESTORE_UNREACHABLE_CODE_WARNINGS \
191 __pragma (warning(pop))
192#else
193#define AUTORTFM_DISABLE_UNREACHABLE_CODE_WARNINGS
194#define AUTORTFM_RESTORE_UNREACHABLE_CODE_WARNINGS
195#endif
196
197#define UE_AUTORTFM_UNUSED(UNUSEDVAR) (void)UNUSEDVAR
198
199// It is critical that these functions are both static and forceinline to prevent binary sizes to explode
200// This is a trick to ensure that there will never be a non-inlined version of these functions that the linker can decide to use
201#ifndef UE_HEADER_UNITS
202#define UE_AUTORTFM_CRITICAL_INLINE static UE_AUTORTFM_FORCEINLINE
203#define UE_AUTORTFM_CRITICAL_INLINE_ALWAYS static UE_AUTORTFM_FORCEINLINE_ALWAYS
204#else
205#define UE_AUTORTFM_CRITICAL_INLINE UE_AUTORTFM_FORCEINLINE // TODO: This needs to be revisited. we don't want bloated executables when modules are enabled
206#define UE_AUTORTFM_CRITICAL_INLINE_ALWAYS UE_AUTORTFM_FORCEINLINE_ALWAYS // TODO: This needs to be revisited. we don't want bloated executables when modules are enabled
207#endif