Debian Codegraph @

mesonbuild/compilers/c_function_attributes.py

raw
1 # These functions are based on the following code:
2 # https://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_gcc_func_attribute.m4,
3 # which is licensed under the following terms:
4 #
5 # Copyright (c) 2013 Gabriele Svelto <[email protected]>
6 #
7 # Copying and distribution of this file, with or without modification, are
8 # permitted in any medium without royalty provided the copyright notice
9 # and this notice are preserved. This file is offered as-is, without any
10 # warranty.
11 #
12
13 C_FUNC_ATTRIBUTES = {
14 'alias': '''
15 int foo(void) { return 0; }
16 int bar(void) __attribute__((alias("foo")));''',
17 'aligned':
18 'int foo(void) __attribute__((aligned(32)));',
19 'alloc_size':
20 'void *foo(int a) __attribute__((alloc_size(1)));',
21 'always_inline':
22 'inline __attribute__((always_inline)) int foo(void) { return 0; }',
23 'artificial':
24 'inline __attribute__((artificial)) int foo(void) { return 0; }',
25 'cold':
26 'int foo(void) __attribute__((cold));',
27 'const':
28 'int foo(void) __attribute__((const));',
29 'constructor':
30 'int foo(void) __attribute__((constructor));',
31 'constructor_priority':
32 'int foo( void ) __attribute__((__constructor__(65535/2)));',
33 'counted_by':
34 '''
35 struct foo {
36 unsigned int count;
37 char bar[] __attribute__((counted_by(count)));
38 };
39 ''',
40 'deprecated':
41 'int foo(void) __attribute__((deprecated("")));',
42 'destructor':
43 'int foo(void) __attribute__((destructor));',
44 'dllexport':
45 '__declspec(dllexport) int foo(void) { return 0; }',
46 'dllimport':
47 '__declspec(dllimport) int foo(void);',
48 'error':
49 'int foo(void) __attribute__((error("")));',
50 'externally_visible':
51 'int foo(void) __attribute__((externally_visible));',
52 'fallthrough': '''
53 int foo( void ) {
54 switch (0) {
55 case 1: __attribute__((fallthrough));
56 case 2: break;
57 }
58 return 0;
59 };''',
60 'flatten':
61 'int foo(void) __attribute__((flatten));',
62 'format':
63 'int foo(const char * p, ...) __attribute__((format(printf, 1, 2)));',
64 'format_arg':
65 'char * foo(const char * p) __attribute__((format_arg(1)));',
66 'force_align_arg_pointer':
67 '__attribute__((force_align_arg_pointer)) int foo(void) { return 0; }',
68 'gnu_inline':
69 'inline __attribute__((gnu_inline)) int foo(void) { return 0; }',
70 'hot':
71 'int foo(void) __attribute__((hot));',
72 'ifunc':
73 ('int my_foo(void) { return 0; }'
74 'static int (*resolve_foo(void))(void) { return my_foo; }'
75 'int foo(void) __attribute__((ifunc("resolve_foo")));'),
76 'leaf':
77 '__attribute__((leaf)) int foo(void) { return 0; }',
78 'malloc':
79 'int *foo(void) __attribute__((malloc));',
80 'noclone':
81 'int foo(void) __attribute__((noclone));',
82 'noinline':
83 '__attribute__((noinline)) int foo(void) { return 0; }',
84 'nonnull':
85 'int foo(char * p) __attribute__((nonnull(1)));',
86 'noreturn':
87 'int foo(void) __attribute__((noreturn));',
88 'nothrow':
89 'int foo(void) __attribute__((nothrow));',
90 'null_terminated_string_arg':
91 'int foo(const char * p) __attribute__((null_terminated_string_arg(1)));',
92 'optimize':
93 '__attribute__((optimize(3))) int foo(void) { return 0; }',
94 'packed':
95 'struct __attribute__((packed)) foo { int bar; };',
96 'pure':
97 'int foo(void) __attribute__((pure));',
98 'returns_nonnull':
99 'int *foo(void) __attribute__((returns_nonnull));',
100 'section': '''
101 #if defined(__APPLE__) && defined(__MACH__)
102 extern int foo __attribute__((section("__BAR,__bar")));
103 #else
104 extern int foo __attribute__((section(".bar")));
105 #endif''',
106 'sentinel':
107 'int foo(const char *bar, ...) __attribute__((sentinel));',
108 'unused':
109 'int foo(void) __attribute__((unused));',
110 'used':
111 'int foo(void) __attribute__((used));',
112 'vector_size':
113 '__attribute__((vector_size(32))); int foo(void) { return 0; }',
114 'visibility': '''
115 int foo_def(void) __attribute__((visibility("default"))); int foo_def(void) { return 0; }
116 int foo_hid(void) __attribute__((visibility("hidden"))); int foo_hid(void) { return 0; }
117 int foo_int(void) __attribute__((visibility("internal"))); int foo_int(void) { return 0; }''',
118 'visibility:default':
119 'int foo(void) __attribute__((visibility("default"))); int foo(void) { return 0; }',
120 'visibility:hidden':
121 'int foo(void) __attribute__((visibility("hidden"))); int foo(void) { return 0; }',
122 'visibility:internal':
123 'int foo(void) __attribute__((visibility("internal"))); int foo(void) { return 0; }',
124 'visibility:protected':
125 'int foo(void) __attribute__((visibility("protected"))); int foo(void) { return 0; }',
126 'warning':
127 'int foo(void) __attribute__((warning("")));',
128 'warn_unused_result':
129 'int foo(void) __attribute__((warn_unused_result));',
130 'weak':
131 'int foo(void) __attribute__((weak));',
132 'weakref': '''
133 static int foo(void) { return 0; }
134 static int var(void) __attribute__((weakref("foo")));''',
135 'retain': '__attribute__((retain)) int x;',
136 }
137
138 CXX_FUNC_ATTRIBUTES = {
139 # Alias must be applied to the mangled name in C++
140 'alias':
141 ('extern "C" {'
142 'int foo(void) { return 0; }'
143 '}'
144 'int bar(void) __attribute__((alias("foo")));'
145 ),
146 'ifunc':
147 ('extern "C" {'
148 'int my_foo(void) { return 0; }'
149 'int (*resolve_foo(void))(void) { return my_foo; }'
150 '}'
151 'int foo(void) __attribute__((ifunc("resolve_foo")));'),
152 }