Debian Codegraph @

test cases/common/197 function attributes/meson.build

raw
1 # Copyright © 2017-2018 Intel Corporation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 project('gcc func attributes', ['c', 'cpp'])
16
17 # For msvc these will fail because msvc doesn't support __attribute__, for
18 # Clang and GCC, they should pass.
19 c = meson.get_compiler('c')
20 cpp = meson.get_compiler('cpp')
21
22 if c.get_id() == 'pgi'
23 error('MESON_SKIP_TEST: PGI supports its own set of features, will need a separate list for PGI to test it.')
24 endif
25
26 expected = {}
27 expected_default = not ['msvc', 'clang-cl', 'intel-cl'].contains(c.get_id())
28
29 # Q: Why is ifunc not in this list or any of the below lists?
30 # A: It's too damn hard to figure out if you actually support it, since it
31 # requires both compiler and libc support, and there isn't a good way to
32 # figure that out except by running the code we're trying to test.
33 attributes = [
34 'aligned',
35 'always_inline',
36 'cold',
37 'const',
38 'constructor',
39 'constructor_priority',
40 'deprecated',
41 'destructor',
42 'flatten',
43 'format',
44 'format_arg',
45 'gnu_inline',
46 'hot',
47 'malloc',
48 'noinline',
49 'nonnull',
50 'noreturn',
51 'nothrow',
52 'pure',
53 'section',
54 'sentinel',
55 'unused',
56 'used',
57 'vector_size',
58 'warn_unused_result',
59 'weak',
60 'dllexport',
61 'dllimport',
62 ]
63
64 expected += {
65 'dllexport': ['windows', 'cygwin'].contains(host_machine.system()),
66 'dllimport': ['windows', 'cygwin'].contains(host_machine.system()),
67 }
68
69 if c.get_id() == 'gcc' and ['windows', 'cygwin'].contains(host_machine.system())
70 expected += {
71 'visibility': false,
72 'visibility:hidden': false,
73 'visibility:internal': false,
74 'visibility:protected': false,
75 }
76 endif
77
78 if c.get_id() != 'intel'
79 # not supported by icc as of 19.0.0
80 attributes += 'weakref'
81 endif
82
83 # These are unsupported on darwin with apple clang 9.1.0
84 if host_machine.system() != 'darwin'
85 attributes += 'alias'
86 attributes += 'visibility'
87 attributes += 'visibility:default'
88 attributes += 'visibility:hidden'
89 attributes += 'visibility:internal'
90 attributes += 'visibility:protected'
91 attributes += 'alloc_size'
92 endif
93
94 # gcc doesn't support constructor_priority on darwin
95 if c.get_id() == 'gcc' and host_machine.system() == 'darwin'
96 expected += {'constructor_priority': false}
97 endif
98
99 if ['gcc', 'intel'].contains(c.get_id())
100 # not supported by clang as of 5.0.0 (at least up to 6.0.1)
101 attributes += 'artificial'
102 attributes += 'error'
103 attributes += 'externally_visible'
104 attributes += 'leaf'
105 attributes += 'noclone'
106 attributes += 'optimize'
107 attributes += 'warning'
108
109 if c.get_id() == 'gcc' and c.version().version_compare('>= 7.0.0')
110 attributes += 'fallthrough'
111 endif
112
113 # XXX(arsen): limited to clang 13+ even though gcc 11 has it, since gcc
114 # detects support for it at compile time based on binutils version
115 if c.get_id() == 'clang' and c.version().version_compare('>= 13.0.0')
116 attributes += 'retain'
117 endif
118 endif
119
120 if c.get_id() == 'clang'
121 if c.version().version_compare('>= 18.0.0')
122 attributes += 'counted_by'
123 endif
124 endif
125
126 if c.get_id() == 'gcc'
127 if c.version().version_compare('>= 15.1')
128 attributes += 'counted_by'
129 endif
130 if c.version().version_compare('>= 14.1')
131 attributes += 'null_terminated_string_arg'
132 endif
133 endif
134
135 if get_option('mode') == 'single'
136 foreach a : attributes
137 x = c.has_function_attribute(a)
138 expected_result = expected.get(a, expected_default)
139 assert(x == expected_result, '@0@: @1@'.format(c.get_id(), a))
140 # counted_by is not currently supported by GCC or clang on C++
141 if a != 'counted_by'
142 x = cpp.has_function_attribute(a)
143 assert(x == expected_result, '@0@: @1@'.format(cpp.get_id(), a))
144 endif
145 endforeach
146 else
147 multi_expected_c = []
148 multi_expected_cpp = []
149 foreach a : attributes
150 if expected.get(a, expected_default)
151 multi_expected_c += a
152 # counted_by is not currently supported by GCC or clang on C++
153 if a != 'counted_by'
154 multi_expected_cpp += a
155 endif
156 endif
157 endforeach
158
159 multi_check = c.get_supported_function_attributes(attributes)
160 assert(multi_check == multi_expected_c, 'get_supported_function_arguments works (C)')
161 multi_check = cpp.get_supported_function_attributes(attributes)
162 assert(multi_check == multi_expected_cpp, 'get_supported_function_arguments works (C++)')
163 endif