From 82bb24b264a1d46c7037b69f1cc10b123bbcf9b5 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 19 Nov 2016 01:28:26 +0200 Subject: [PATCH] Made has_function survive optimization flags. Closes #1053. --- mesonbuild/compilers.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index fef4c1df1..ced2b6fb5 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -927,9 +927,11 @@ int main(int argc, char **argv) { """ # Add the 'prefix', aka defines, includes, etc that the user provides head = '#include \n{0}\n' - # We don't know what the function takes or returns, so try to use it as - # a function pointer - main = '\nint main() {{ void *a = (void*) &{1}; }}' + # We don't know what the function takes or returns, so return it as an int. + # Just taking the address or comparing it to void is not enough because + # compilers are smart enough to optimize it away. The resulting binary + # is not run so we don't care what the return value is. + main = '\nint main() {{ void *a = (void*) &{1}; long b = (long) a; return (int) b; }}' return head, main def has_function(self, funcname, prefix, env, extra_args=None, dependencies=None):