Fix builtin check in has_function() with GCC 10 on Windows

The builtin check had a special case that if a header was provided and
the function wasn't defined, it would ignore the builtin to avoid
non-functional builtins (for example __builtin_posix_memalign in MSYS2).

GCC 10 gained support for __has_builtin() which now skipps this check
and because __has_builtin(__builtin_posix_memalign) returns true the
non functional builtin is now reported as available.

To get the old behaviour back move the special case in front of the actual
availability check.

Fixes #7113
pull/7121/head
Christoph Reiter 5 years ago committed by Dylan Baker
parent efb86088bc
commit d7e20b1543
  1. 27
      mesonbuild/compilers/mixins/clike.py

@ -727,24 +727,29 @@ class CLikeCompiler:
# need to look for them differently. On nice compilers like clang, we
# can just directly use the __has_builtin() macro.
fargs['no_includes'] = '#include' not in prefix
fargs['__builtin_'] = '' if funcname.startswith('__builtin_') else '__builtin_'
is_builtin = funcname.startswith('__builtin_')
fargs['is_builtin'] = is_builtin
fargs['__builtin_'] = '' if is_builtin else '__builtin_'
t = '''{prefix}
int main(void) {{
/* With some toolchains (MSYS2/mingw for example) the compiler
* provides various builtins which are not really implemented and
* fall back to the stdlib where they aren't provided and fail at
* build/link time. In case the user provides a header, including
* the header didn't lead to the function being defined, and the
* function we are checking isn't a builtin itself we assume the
* builtin is not functional and we just error out. */
#if !{no_includes:d} && !defined({func}) && !{is_builtin:d}
#error "No definition for {__builtin_}{func} found in the prefix"
#endif
#ifdef __has_builtin
#if !__has_builtin({__builtin_}{func})
#error "{__builtin_}{func} not found"
#endif
#elif ! defined({func})
/* Check for {__builtin_}{func} only if no includes were added to the
* prefix above, which means no definition of {func} can be found.
* We would always check for this, but we get false positives on
* MSYS2 if we do. Their toolchain is broken, but we can at least
* give them a workaround. */
#if {no_includes:d}
{__builtin_}{func};
#else
#error "No definition for {__builtin_}{func} found in the prefix"
#endif
{__builtin_}{func};
#endif
return 0;
}}'''

Loading…
Cancel
Save