diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2017-09-29 11:52:06 -0700 |
|---|---|---|
| committer | Nirbheek Chauhan <nirbheek.chauhan@gmail.com> | 2018-09-07 11:52:15 -0700 |
| commit | 51e9db370a0ebccaf220e171c3444a0f2c4e1723 (patch) | |
| tree | 1636eec99faf01aeb6e08c0753fa4503fdbdbb38 /test cases | |
| parent | 8ca463f9f1d432d059c12da42a18fd13b4604b57 (diff) | |
| download | meson-51e9db370a0ebccaf220e171c3444a0f2c4e1723.tar.gz | |
Add method to check for C/C++ function attributes
It's fairly common on Linux and *BSD platforms to check for these
attributes existence, so it makes sense to me to have this checking
build into meson itself. Autotools also has a builtin for handling
these, and by building them in we can short circuit cases that we know
that these don't exist (MSVC).
Additionally this adds support for two common MSVC __declspec
attributes, dllimport and dllexport. This implements the declspec
version (even though GCC has an __attribute__ version that both it and
clang support), since GCC and Clang support the MSVC version as well.
Thus it seems reasonable to assume that most projects will use the
__declspec version over teh __attribute__ version.
Diffstat (limited to 'test cases')
| -rw-r--r-- | test cases/common/204 function attributes/meson.build | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/test cases/common/204 function attributes/meson.build b/test cases/common/204 function attributes/meson.build new file mode 100644 index 000000000..bc049d7d0 --- /dev/null +++ b/test cases/common/204 function attributes/meson.build @@ -0,0 +1,103 @@ +# Copyright © 2017-2018 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +project('gcc func attributes', ['c', 'cpp']) + +# For msvc these will fail because msvc doesn't support __attribute__, for +# Clang and GCC, they should pass. +c = meson.get_compiler('c') +cpp = meson.get_compiler('cpp') + +expected_result = c.get_id() != 'msvc' + +# Q: Why is ifunc not in this list or any of the below lists? +# A: It's too damn hard to figure out if you actually support it, since it +# requires both compiler and libc support, and there isn't a good way to +# figure that out except by running the code we're trying to test. +attributes = [ + 'aligned', + 'alloc_size', + 'always_inline', + 'cold', + 'const', + 'constructor', + 'constructor_priority', + 'deprecated', + 'destructor', + 'flatten', + 'format', + 'format_arg', + 'gnu_inline', + 'hot', + 'malloc', + 'noinline', + 'nonnull', + 'noreturn', + 'nothrow', + 'pure', + 'unused', + 'used', + 'warn_unused_result', + 'weak', + 'weakref', +] + +# These are unsupported on darwin with apple clang 9.1.0 +if host_machine.system() != 'darwin' + attributes += 'alias' + attributes += 'visibility' +endif + +if c.get_id() == 'gcc' + # not supported by clang as of 5.0.0 (at least up to 6.0.1) + attributes += 'artificial' + attributes += 'error' + attributes += 'externally_visible' + attributes += 'leaf' + attributes += 'noclone' + attributes += 'optimize' + attributes += 'warning' + + if c.version().version_compare('>= 7.0.0') + attributes += 'fallthrough' + endif +endif + + +foreach a : attributes + x = c.has_function_attribute(a) + assert(x == expected_result, '@0@: @1@'.format(c.get_id(), a)) + x = cpp.has_function_attribute(a) + assert(x == expected_result, '@0@: @1@'.format(cpp.get_id(), a)) +endforeach + +win_expect = ['windows', 'cygwin'].contains(host_machine.system()) +foreach a : ['dllexport', 'dllimport'] + assert(c.has_function_attribute(a) == win_expect, + '@0@: @1@'.format(c.get_id(), a)) + assert(cpp.has_function_attribute(a) == win_expect, + '@0@: @1@'.format(cpp.get_id(), a)) +endforeach + +message('checking get_supported_function_attributes') +if c.get_id() != 'msvc' + multi_expected = attributes +else + multi_expected = [] +endif + +multi_check = c.get_supported_function_attributes(attributes) +assert(multi_check == multi_expected, 'get_supported_function_arguments works (C)') +multi_check = cpp.get_supported_function_attributes(attributes) +assert(multi_check == multi_expected, 'get_supported_function_arguments works (C++)') |
