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