From 9a9654c4bdfeeab78b602a27615ab1845b7ba383 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 15 Apr 2016 17:44:00 +0530 Subject: [PATCH 1/2] Fix off-by-one in cross_sizeof and cross_alignment on MSVC --- mesonbuild/compilers.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 8dee468a7..e9a798d59 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -596,6 +596,10 @@ int temparray[%d-sizeof(%s)]; for i in range(1, 1024): code = templ % (prefix, i, element) if self.compiles(code, extra_args): + if self.id == 'msvc': + # MSVC refuses to construct an array of zero size, so + # the test only succeeds when i is sizeof(element) + 1 + return i - 1 return i raise EnvironmentException('Cross checking sizeof overflowed.') @@ -633,6 +637,10 @@ int testarray[%d-offsetof(struct tmp, target)]; for i in range(1, 1024): code = templ % (typename, i) if self.compiles(code, extra_args): + if self.id == 'msvc': + # MSVC refuses to construct an array of zero size, so + # the test only succeeds when i is sizeof(element) + 1 + return i - 1 return i raise EnvironmentException('Cross checking offsetof overflowed.') From 2c687b02c2cd88c4c147932faefe071c34176cdb Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 15 Apr 2016 17:48:54 +0530 Subject: [PATCH 2/2] Fix symbol-exists check for cross_sizeof and add the same check to cross_alignment The previous check was failing while checking pointer sizes such as void* due to a syntax error. --- mesonbuild/compilers.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index e9a798d59..1915644e6 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -579,7 +579,7 @@ int main () {{ {1}; }}''' element_exists_templ = '''#include {0} int main(int argc, char **argv) {{ - {1}; + {1} something; }} ''' templ = '''#include @@ -622,6 +622,11 @@ int main(int argc, char **argv) { return int(res.stdout) def cross_alignment(self, typename, env, extra_args=[]): + type_exists_templ = '''#include +int main(int argc, char **argv) {{ + {0} something; +}} +''' templ = '''#include struct tmp { char c; @@ -634,6 +639,9 @@ int testarray[%d-offsetof(struct tmp, target)]; extra_args += env.cross_info.config['properties'][self.language + '_args'] except KeyError: pass + extra_args += self.get_no_optimization_args() + if not self.compiles(type_exists_templ.format(typename)): + return -1 for i in range(1, 1024): code = templ % (typename, i) if self.compiles(code, extra_args):