Blender  V3.3
BLI_compiler_attrs.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2013 Blender Foundation. All rights reserved. */
3 
4 #pragma once
5 
10 /* hint to make sure function result is actually used */
11 #ifdef __GNUC__
12 # define ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
13 #else
14 # define ATTR_WARN_UNUSED_RESULT
15 #endif
16 
17 /* hint to mark function arguments expected to be non-null
18  * if no arguments are given to the macro, all of pointer
19  * arguments would be expected to be non-null
20  */
21 #ifdef __GNUC__
22 # define ATTR_NONNULL(args...) __attribute__((nonnull(args)))
23 #else
24 # define ATTR_NONNULL(...)
25 #endif
26 
27 /* never returns NULL */
28 #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 409 /* gcc4.9+ only */
29 # define ATTR_RETURNS_NONNULL __attribute__((returns_nonnull))
30 #else
31 # define ATTR_RETURNS_NONNULL
32 #endif
33 
34 /* hint to mark function as it wouldn't return */
35 #if defined(__GNUC__) || defined(__clang__)
36 # define ATTR_NORETURN __attribute__((noreturn))
37 #else
38 # define ATTR_NORETURN
39 #endif
40 
41 /* hint to treat any non-null function return value cannot alias any other pointer */
42 #if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403))
43 # define ATTR_MALLOC __attribute__((malloc))
44 #else
45 # define ATTR_MALLOC
46 #endif
47 
48 /* the function return value points to memory (2 args for 'size * tot') */
49 #if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403))
50 # define ATTR_ALLOC_SIZE(args...) __attribute__((alloc_size(args)))
51 #else
52 # define ATTR_ALLOC_SIZE(...)
53 #endif
54 
55 /* ensures a NULL terminating argument as the n'th last argument of a variadic function */
56 #ifdef __GNUC__
57 # define ATTR_SENTINEL(arg_pos) __attribute__((sentinel(arg_pos)))
58 #else
59 # define ATTR_SENTINEL(arg_pos)
60 #endif
61 
62 /* hint to compiler that function uses printf-style format string */
63 #ifdef __GNUC__
64 # define ATTR_PRINTF_FORMAT(format_param, dots_param) \
65  __attribute__((format(printf, format_param, dots_param)))
66 #else
67 # define ATTR_PRINTF_FORMAT(format_param, dots_param)
68 #endif
69 
70 /* Use to suppress '-Wimplicit-fallthrough' (in place of 'break'). */
71 #ifndef ATTR_FALLTHROUGH
72 # if defined(__GNUC__) && (__GNUC__ >= 7) /* gcc7.0+ only */
73 # define ATTR_FALLTHROUGH __attribute__((fallthrough))
74 # else
75 # define ATTR_FALLTHROUGH ((void)0)
76 # endif
77 #endif
78 
79 /* Declare the memory alignment in Bytes. */
80 #if defined(_WIN32) && !defined(FREE_WINDOWS)
81 # define ATTR_ALIGN(x) __declspec(align(x))
82 #else
83 # define ATTR_ALIGN(x) __attribute__((aligned(x)))
84 #endif
85 
86 /* Alignment directive */
87 #ifdef _WIN64
88 # define ALIGN_STRUCT __declspec(align(64))
89 #else
90 # define ALIGN_STRUCT
91 #endif