Mesa (master): meson: Use builtins for checking gnu __attributes__

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jun 1 19:48:43 UTC 2020


Module: Mesa
Branch: master
Commit: 17dcd535c1973fb8bdaba9eb013672825cc10b94
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=17dcd535c1973fb8bdaba9eb013672825cc10b94

Author: Dylan Baker <dylan.c.baker at intel.com>
Date:   Fri Apr 24 12:39:27 2020 -0700

meson: Use builtins for checking gnu __attributes__

This requires less code, and will fast skip on compilers that are known
to not have these, like MSVC.

Acked-by: Matt Turner <mattst88 at gmail.com>
Reviewed-by: Eric Engestrom <eric at engestrom.ch>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4740>

---

 meson.build | 38 +++++++-------------------------------
 1 file changed, 7 insertions(+), 31 deletions(-)

diff --git a/meson.build b/meson.build
index bebb900d10a..2365874bc3f 100644
--- a/meson.build
+++ b/meson.build
@@ -839,40 +839,16 @@ foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
 endforeach
 
 # check for GCC __attribute__
-foreach a : ['const', 'flatten', 'malloc', 'pure', 'unused',
-             'warn_unused_result', 'weak',]
-  if cc.compiles('int foo(void) __attribute__((@0@));'.format(a),
-                 name : '__attribute__((@0@))'.format(a))
-    pre_args += '-DHAVE_FUNC_ATTRIBUTE_ at 0@'.format(a.to_upper())
-  endif
+_attributes = [
+  'const', 'flatten', 'malloc', 'pure', 'unused', 'warn_unused_result',
+  'weak', 'format', 'packed', 'returns_nonnull', 'alias', 'noreturn',
+]
+foreach a : cc.get_supported_function_attributes(_attributes)
+  pre_args += '-DHAVE_FUNC_ATTRIBUTE_ at 0@'.format(a.to_upper())
 endforeach
-if cc.compiles('int foo(const char *p, ...) __attribute__((format(printf, 1, 2)));',
-               name : '__attribute__((format(...)))')
-  pre_args += '-DHAVE_FUNC_ATTRIBUTE_FORMAT'
-endif
-if cc.compiles('struct __attribute__((packed)) foo { int bar; };',
-               name : '__attribute__((packed))')
-  pre_args += '-DHAVE_FUNC_ATTRIBUTE_PACKED'
-endif
-if cc.compiles('int *foo(void) __attribute__((returns_nonnull));',
-               name : '__attribute__((returns_nonnull))')
-  pre_args += '-DHAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL'
-endif
-if cc.compiles('''int foo_def(void) __attribute__((visibility("default")));
-                  int foo_hid(void) __attribute__((visibility("hidden")));
-                  int foo_int(void) __attribute__((visibility("internal")));
-                  int foo_pro(void) __attribute__((visibility("protected")));''',
-               name : '__attribute__((visibility(...)))')
+if cc.has_function_attribute('visibility:hidden')
   pre_args += '-DHAVE_FUNC_ATTRIBUTE_VISIBILITY'
 endif
-if cc.compiles('int foo(void) { return 0; } int bar(void) __attribute__((alias("foo")));',
-               name : '__attribute__((alias(...)))')
-  pre_args += '-DHAVE_FUNC_ATTRIBUTE_ALIAS'
-endif
-if cc.compiles('int foo(void) __attribute__((__noreturn__));',
-               name : '__attribute__((__noreturn__))')
-  pre_args += '-DHAVE_FUNC_ATTRIBUTE_NORETURN'
-endif
 if cc.compiles('__uint128_t foo(void) { return 0; }',
                name : '__uint128_t')
   pre_args += '-DHAVE_UINT128'



More information about the mesa-commit mailing list