From fbbfbfac7e13ad2fb594f52678652afc262c1005 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 23 Jan 2017 23:19:51 +0530 Subject: [PATCH] compilers: Fix builtin checks with clang on Linux Our "43 has function" test should also work with clang and icc on Linux, so enable them. Also detect builtins with __has_builtin if available, which is much faster on clang. There is a feature request for the same with GCC too: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66970 --- mesonbuild/compilers.py | 11 ++++++++++- test cases/common/43 has function/meson.build | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 23e7bbe4b..43d3356e5 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -1057,7 +1057,16 @@ int main(int argc, char **argv) { # posix_memalign in the headers to point to that builtin which results # in an invalid detection. if '#include' not in prefix: - code = 'int main() {{ {0}; }}' + code = ''' + int main() {{ + #ifdef __has_builtin + #if !__has_builtin({0}) + #error "built-in {0} not found" + #endif + #else + {0}; + #endif + }}''' return self.links(code.format('__builtin_' + funcname), env, extra_args, dependencies) else: diff --git a/test cases/common/43 has function/meson.build b/test cases/common/43 has function/meson.build index 323ed0093..b2bb43a20 100644 --- a/test cases/common/43 has function/meson.build +++ b/test cases/common/43 has function/meson.build @@ -31,12 +31,16 @@ foreach cc : compilers error('Found non-existent function "hfkerhisadf".') endif + if cc.has_function('hfkerhisadf', args : unit_test_args) + error('Found non-existent function "hfkerhisadf".') + endif + # With glibc on Linux lchmod is a stub that will always return an error, # we want to detect that and declare that the function is not available. # We can't check for the C library used here of course, but if it's not # implemented in glibc it's probably not implemented in any other 'slimmer' # C library variants either, so the check should be safe either way hopefully. - if host_system == 'linux' and cc.get_id() == 'gcc' + if host_system == 'linux' assert (cc.has_function('poll', prefix : '#include ', args : unit_test_args), 'couldn\'t detect "poll" when defined by a header')