compiler: Define NO_RETURN for MSVC.
authorGurucharan Shetty <gshetty@nicira.com>
Mon, 15 Sep 2014 19:58:09 +0000 (12:58 -0700)
committerGurucharan Shetty <gshetty@nicira.com>
Mon, 15 Sep 2014 22:15:35 +0000 (15:15 -0700)
To prevent warnings such as "Not all control paths return a value",
we should define NO_RETURN for MSVC.

Currently for gcc, we add NO_RETURN at the end of function declaration.
But for MSVC, "__declspec(noreturn)" is needed at the beginning of function
declaration. So this commit moves NO_RETURN to the beginning of the function
declaration as it works with gcc and clang too.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
20 files changed:
lib/compiler.h
lib/stream-nossl.c
lib/util.h
lib/vlog.h
ovsdb/ovsdb-client.c
ovsdb/ovsdb-server.c
ovsdb/ovsdb-tool.c
tests/test-jsonrpc.c
tests/test-netflow.c
tests/test-ovsdb.c
tests/test-rstp.c
tests/test-sflow.c
tests/test-stp.c
utilities/ovs-dpctl.c
utilities/ovs-ofctl.c
utilities/ovs-testcontroller.c
utilities/ovs-vsctl.c
vswitchd/ovs-vswitchd.c
vswitchd/system-stats.c
vtep/vtep-ctl.c

index 5942c30..629d09b 100644 (file)
   #define __has_extension(x) 0
 #endif
 
+/* To make NO_RETURN portable across gcc/clang and MSVC, it should be
+ * added at the beginning of the function declaration. */
 #if __GNUC__ && !__CHECKER__
 #define NO_RETURN __attribute__((__noreturn__))
+#elif _MSC_VER
+#define NO_RETURN __declspec(noreturn)
+#else
+#define NO_RETURN
+#endif
+
+#if __GNUC__ && !__CHECKER__
 #define OVS_UNUSED __attribute__((__unused__))
 #define PRINTF_FORMAT(FMT, ARG1) __attribute__((__format__(printf, FMT, ARG1)))
 #define SCANF_FORMAT(FMT, ARG1) __attribute__((__format__(scanf, FMT, ARG1)))
@@ -37,7 +46,6 @@
 #define OVS_LIKELY(CONDITION) __builtin_expect(!!(CONDITION), 1)
 #define OVS_UNLIKELY(CONDITION) __builtin_expect(!!(CONDITION), 0)
 #else
-#define NO_RETURN
 #define OVS_UNUSED
 #define PRINTF_FORMAT(FMT, ARG1)
 #define SCANF_FORMAT(FMT, ARG1)
index 23bc1fb..7dc5e0f 100644 (file)
@@ -28,7 +28,7 @@ stream_ssl_is_configured(void)
     return false;
 }
 
-static void NO_RETURN
+NO_RETURN static void
 nossl_option(const char *detail)
 {
     VLOG_FATAL("%s specified but Open vSwitch was built without SSL support",
index a2c6ee9..7da7aa8 100644 (file)
@@ -74,7 +74,7 @@
     if (!OVS_LIKELY(CONDITION)) {                                       \
         ovs_assert_failure(SOURCE_LOCATOR, __func__, #CONDITION);       \
     }
-void ovs_assert_failure(const char *, const char *, const char *) NO_RETURN;
+NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
 
 /* Casts 'pointer' to 'type' and issues a compiler warning if the cast changes
  * anything other than an outermost "const" or "volatile" qualifier.
@@ -275,7 +275,7 @@ void set_subprogram_name(const char *format, ...) PRINTF_FORMAT(1, 2);
 const char *get_program_version(void);
 void ovs_print_version(uint8_t min_ofp, uint8_t max_ofp);
 
-void out_of_memory(void) NO_RETURN;
+NO_RETURN void out_of_memory(void);
 void *xmalloc(size_t) MALLOC_LIKE;
 void *xcalloc(size_t, size_t) MALLOC_LIKE;
 void *xzalloc(size_t) MALLOC_LIKE;
@@ -294,14 +294,14 @@ void free_cacheline(void *);
 void ovs_strlcpy(char *dst, const char *src, size_t size);
 void ovs_strzcpy(char *dst, const char *src, size_t size);
 
-void ovs_abort(int err_no, const char *format, ...)
-    PRINTF_FORMAT(2, 3) NO_RETURN;
-void ovs_abort_valist(int err_no, const char *format, va_list)
-    PRINTF_FORMAT(2, 0) NO_RETURN;
-void ovs_fatal(int err_no, const char *format, ...)
-    PRINTF_FORMAT(2, 3) NO_RETURN;
-void ovs_fatal_valist(int err_no, const char *format, va_list)
-    PRINTF_FORMAT(2, 0) NO_RETURN;
+NO_RETURN void ovs_abort(int err_no, const char *format, ...)
+    PRINTF_FORMAT(2, 3);
+NO_RETURN void ovs_abort_valist(int err_no, const char *format, va_list)
+    PRINTF_FORMAT(2, 0);
+NO_RETURN void ovs_fatal(int err_no, const char *format, ...)
+    PRINTF_FORMAT(2, 3);
+NO_RETURN void ovs_fatal_valist(int err_no, const char *format, va_list)
+    PRINTF_FORMAT(2, 0);
 void ovs_error(int err_no, const char *format, ...) PRINTF_FORMAT(2, 3);
 void ovs_error_valist(int err_no, const char *format, va_list)
     PRINTF_FORMAT(2, 0);
index e5af21d..974a301 100644 (file)
@@ -154,15 +154,17 @@ void vlog_valist(const struct vlog_module *, enum vlog_level,
                  const char *, va_list)
     PRINTF_FORMAT (3, 0);
 
-void vlog_fatal(const struct vlog_module *, const char *format, ...)
-    PRINTF_FORMAT (2, 3) NO_RETURN;
-void vlog_fatal_valist(const struct vlog_module *, const char *format, va_list)
-    PRINTF_FORMAT (2, 0) NO_RETURN;
-
-void vlog_abort(const struct vlog_module *, const char *format, ...)
-    PRINTF_FORMAT (2, 3) NO_RETURN;
-void vlog_abort_valist(const struct vlog_module *, const char *format, va_list)
-    PRINTF_FORMAT (2, 0) NO_RETURN;
+NO_RETURN void vlog_fatal(const struct vlog_module *, const char *format, ...)
+    PRINTF_FORMAT (2, 3);
+NO_RETURN void vlog_fatal_valist(const struct vlog_module *,
+                                 const char *format, va_list)
+    PRINTF_FORMAT (2, 0);
+
+NO_RETURN void vlog_abort(const struct vlog_module *, const char *format, ...)
+    PRINTF_FORMAT (2, 3);
+NO_RETURN void vlog_abort_valist(const struct vlog_module *,
+                                 const char *format, va_list)
+    PRINTF_FORMAT (2, 0);
 
 void vlog_rate_limit(const struct vlog_module *, enum vlog_level,
                      struct vlog_rate_limit *, const char *, ...)
index 2942953..2f1a837 100644 (file)
@@ -74,7 +74,7 @@ static struct table_style table_style = TABLE_STYLE_DEFAULT;
 
 static const struct ovsdb_client_command *get_all_commands(void);
 
-static void usage(void) NO_RETURN;
+NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[]);
 static struct jsonrpc *open_jsonrpc(const char *server);
 static void fetch_dbs(struct jsonrpc *, struct svec *dbs);
index 7dc2adb..6219110 100644 (file)
@@ -97,7 +97,7 @@ static void close_db(struct db *db);
 static void parse_options(int *argc, char **argvp[],
                           struct sset *remotes, char **unixctl_pathp,
                           char **run_command);
-static void usage(void) NO_RETURN;
+NO_RETURN static void usage(void);
 
 static char *reconfigure_remotes(struct ovsdb_jsonrpc_server *,
                                  const struct shash *all_dbs,
index e2a30ea..350e72a 100644 (file)
@@ -46,7 +46,7 @@ static int show_log_verbosity;
 
 static const struct command *get_all_commands(void);
 
-static void usage(void) NO_RETURN;
+NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[]);
 
 static const char *default_db(void);
index dbd0b52..cf90c44 100644 (file)
@@ -35,7 +35,7 @@
 #include "vlog.h"
 #include "ovstest.h"
 
-static void usage(void) NO_RETURN;
+NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[]);
 static struct command *get_all_commands(void);
 
index 76f9bae..284d7ab 100644 (file)
@@ -35,7 +35,7 @@
 #include "vlog.h"
 #include "ovstest.h"
 
-static void usage(void) NO_RETURN;
+NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[]);
 
 static unixctl_cb_func test_netflow_exit;
index ebb24c0..4d73a0d 100644 (file)
@@ -51,7 +51,7 @@
 #include "util.h"
 #include "vlog.h"
 
-static void usage(void) NO_RETURN;
+NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[]);
 static struct command *get_all_commands(void);
 
index afc5b60..96c611a 100644 (file)
@@ -335,10 +335,9 @@ simulate(struct test_case *tc, int granularity)
     }
 }
 
-static void
+NO_RETURN static void
 err(const char *message, ...)
-    PRINTF_FORMAT(1, 2)
-    NO_RETURN;
+    PRINTF_FORMAT(1, 2);
 
 static void
 err(const char *message, ...)
index b91fd41..1d512ad 100644 (file)
@@ -38,7 +38,7 @@
 #include "vlog.h"
 #include "ovstest.h"
 
-static void usage(void) NO_RETURN;
+NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[]);
 
 static unixctl_cb_func test_sflow_exit;
index c4e5933..45f0f4c 100644 (file)
@@ -316,10 +316,9 @@ simulate(struct test_case *tc, int granularity)
     }
 }
 
-static void
+NO_RETURN static void
 err(const char *message, ...)
-    PRINTF_FORMAT(1, 2)
-    NO_RETURN;
+    PRINTF_FORMAT(1, 2);
 
 static void
 err(const char *message, ...)
index 6c25bfd..94a6b90 100644 (file)
@@ -44,7 +44,7 @@
 
 static struct dpctl_params dpctl_p;
 
-static void usage(void *userdata OVS_UNUSED) NO_RETURN;
+NO_RETURN static void usage(void *userdata OVS_UNUSED);
 static void parse_options(int argc, char *argv[]);
 
 static void
index 30cdf99..4a90155 100644 (file)
@@ -106,7 +106,7 @@ static size_t n_criteria, allocated_criteria;
 
 static const struct command *get_all_commands(void);
 
-static void usage(void) NO_RETURN;
+NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[]);
 
 static bool recv_flow_stats_reply(struct vconn *, ovs_be32 send_xid,
index a615ab4..4ef7d4b 100644 (file)
@@ -91,7 +91,7 @@ static char *unixctl_path = NULL;
 
 static void new_switch(struct switch_ *, struct vconn *);
 static void parse_options(int argc, char *argv[]);
-static void usage(void) NO_RETURN;
+NO_RETURN static void usage(void);
 
 int
 main(int argc, char *argv[])
index 5cf12cf..818184a 100644 (file)
@@ -137,10 +137,10 @@ static const struct vsctl_command_syntax *get_all_commands(void);
 static struct ovsdb_idl *the_idl;
 static struct ovsdb_idl_txn *the_idl_txn;
 
-static void vsctl_exit(int status) NO_RETURN;
-static void vsctl_fatal(const char *, ...) PRINTF_FORMAT(1, 2) NO_RETURN;
+NO_RETURN static void vsctl_exit(int status);
+NO_RETURN static void vsctl_fatal(const char *, ...) PRINTF_FORMAT(1, 2);
 static char *default_db(void);
-static void usage(void) NO_RETURN;
+NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[], struct shash *local_options);
 static bool might_write_to_db(char **argv);
 
index 4d7e4f0..b0d08e8 100644 (file)
@@ -59,7 +59,7 @@ static bool want_mlockall;
 static unixctl_cb_func ovs_vswitchd_exit;
 
 static char *parse_options(int argc, char *argv[], char **unixctl_path);
-static void usage(void) NO_RETURN;
+NO_RETURN static void usage(void);
 
 int
 main(int argc, char *argv[])
index 7789787..dc0f2c5 100644 (file)
@@ -531,7 +531,7 @@ static bool enabled;
 static bool started OVS_GUARDED_BY(mutex);
 static struct smap *system_stats OVS_GUARDED_BY(mutex);
 
-static void *system_stats_thread_func(void *);
+NO_RETURN static void *system_stats_thread_func(void *);
 static void discard_stats(void);
 
 /* Enables or disables system stats collection, according to 'enable'. */
@@ -604,7 +604,7 @@ discard_stats(void) OVS_REQUIRES(mutex)
     }
 }
 
-static void * NO_RETURN
+static void *
 system_stats_thread_func(void *arg OVS_UNUSED)
 {
     pthread_detach(pthread_self());
index 3576313..8a16450 100644 (file)
@@ -121,10 +121,10 @@ static struct table_style table_style = TABLE_STYLE_DEFAULT;
 static struct ovsdb_idl *the_idl;
 static struct ovsdb_idl_txn *the_idl_txn;
 
-static void vtep_ctl_exit(int status) NO_RETURN;
-static void vtep_ctl_fatal(const char *, ...) PRINTF_FORMAT(1, 2) NO_RETURN;
+NO_RETURN static void vtep_ctl_exit(int status);
+NO_RETURN static void vtep_ctl_fatal(const char *, ...) PRINTF_FORMAT(1, 2);
 static char *default_db(void);
-static void usage(void) NO_RETURN;
+NO_RETURN static void usage(void);
 static void parse_options(int argc, char *argv[], struct shash *local_options);
 static bool might_write_to_db(char **argv);