build: lib/util/string_wrappers.h: fix optimisation check for clang
authorRalph Boehme <slow@samba.org>
Sat, 11 Oct 2014 18:50:46 +0000 (20:50 +0200)
committerVolker Lendecke <vl@samba.org>
Mon, 20 Oct 2014 12:41:09 +0000 (14:41 +0200)
Building with clang resulted in an error with undefined symbols
___unsafe_string_function_usage_here_size_t__ etc. Turns out the
existing check whether the compiler optimizes out functions doesn't
match the use case, ie the check said yes, but the functions were not
optimized out.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Mon Oct 20 14:41:09 CEST 2014 on sn-devel-104

source3/wscript

index 4f182bf748124a459669da6d4b0103d2a24cff12..2083f01a8db0a6220d01d6e3a9985a426e497977 100644 (file)
@@ -349,12 +349,28 @@ int main(int argc, char **argv)
 
     # Check if the compiler will optimize out functions
     conf.CHECK_CODE('''
-if (0) {
-    this_function_does_not_exist();
-} else {
-    return 1;
+#include <sys/types.h>
+size_t __unsafe_string_function_usage_here_size_t__(void);
+#define CHECK_STRING_SIZE(d, len) (sizeof(d) != (len) && sizeof(d) != sizeof(char *))
+static size_t push_string_check_fn(void *dest, const char *src, size_t dest_len) {
+       return 0;
+}
+
+#define push_string_check(dest, src, dest_len) \
+    (CHECK_STRING_SIZE(dest, dest_len) \
+    ? __unsafe_string_function_usage_here_size_t__()   \
+    : push_string_check_fn(dest, src, dest_len))
+
+int main(int argc, char **argv) {
+    char outbuf[1024];
+    char *p = outbuf;
+    const char *foo = "bar";
+    p += 31 + push_string_check(p + 31, foo, sizeof(outbuf) - (p + 31 - outbuf));
+    return 0;
 }''', 'HAVE_COMPILER_WILL_OPTIMIZE_OUT_FNS',
-        msg="Checking if the compiler will optimize out functions")
+            addmain=False,
+            add_headers=False,
+            msg="Checking if the compiler will optimize out functions")
 
     # Check if the compiler supports the LL suffix on long long integers
     # AIX needs this