[ovs-dev] [clang-atomics 4/4] ovs-thread: Work around apparent Clang bug.

Ben Pfaff blp at nicira.com
Tue Aug 20 18:10:15 UTC 2013


Without this patch, I get Clang warnings that I don't understand for each
of the non-static functions in dirs.c:

    warning: control reaches end of non-void function

I get the same warning for this test program with "clang -c -Wall":

    struct foo {
         const char *y;
        _Atomic(int) x;
    };

    const char *
    bar(const struct foo *fp)
    {
       return fp->y;
    }

    const char *f(void)
    {
        static struct foo f = {"xyzzy", 0};
        return bar(&f);
    }

If I change {"xyzzy", 0} to just {"xyzzy"}, the warning goes away, and the
same is true for the current patch.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 lib/ovs-thread.h |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/ovs-thread.h b/lib/ovs-thread.h
index fb76954..dc56d83 100644
--- a/lib/ovs-thread.h
+++ b/lib/ovs-thread.h
@@ -460,11 +460,18 @@ struct ovsthread_once {
     struct ovs_mutex mutex;
 };
 
+#if !OVS_ATOMIC_CLANG_IMPL
 #define OVSTHREAD_ONCE_INITIALIZER              \
     {                                           \
         ATOMIC_VAR_INIT(false),                 \
         OVS_ADAPTIVE_MUTEX_INITIALIZER,         \
     }
+#else  /* OVS_ATOMIC_CLANG_IMPL */
+/* Clang 3.4-1~exp1 has some odd ideas about initializers: if we use the
+ * conventional initializer above, then it complains that "warning: control
+ * reaches end of non-void function" in each of the functions in lib/dirs.c. */
+#define OVSTHREAD_ONCE_INITIALIZER { .mutex = OVS_ADAPTIVE_MUTEX_INITIALIZER }
+#endif
 
 static inline bool ovsthread_once_start(struct ovsthread_once *once)
     OVS_TRY_LOCK(true, once->mutex);
-- 
1.7.10.4




More information about the dev mailing list