From: Gurucharan Shetty Date: Mon, 15 Sep 2014 19:58:09 +0000 (-0700) Subject: compiler: Define NO_RETURN for MSVC. X-Git-Tag: v2.4.0~1403 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=270f328621bfd8f80659150d5d3eec51754b5bfb compiler: Define NO_RETURN for MSVC. 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 Acked-by: Ben Pfaff --- diff --git a/lib/compiler.h b/lib/compiler.h index 5942c3029..629d09bf8 100644 --- a/lib/compiler.h +++ b/lib/compiler.h @@ -24,8 +24,17 @@ #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) diff --git a/lib/stream-nossl.c b/lib/stream-nossl.c index 23bc1fbdf..7dc5e0f7c 100644 --- a/lib/stream-nossl.c +++ b/lib/stream-nossl.c @@ -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", diff --git a/lib/util.h b/lib/util.h index a2c6ee9c5..7da7aa8f0 100644 --- a/lib/util.h +++ b/lib/util.h @@ -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); diff --git a/lib/vlog.h b/lib/vlog.h index e5af21d61..974a30190 100644 --- a/lib/vlog.h +++ b/lib/vlog.h @@ -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 *, ...) diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c index 29429531b..2f1a8372a 100644 --- a/ovsdb/ovsdb-client.c +++ b/ovsdb/ovsdb-client.c @@ -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); diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index 7dc2adbc2..6219110b8 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -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, diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c index e2a30ea72..350e72af6 100644 --- a/ovsdb/ovsdb-tool.c +++ b/ovsdb/ovsdb-tool.c @@ -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); diff --git a/tests/test-jsonrpc.c b/tests/test-jsonrpc.c index dbd0b5210..cf90c4434 100644 --- a/tests/test-jsonrpc.c +++ b/tests/test-jsonrpc.c @@ -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); diff --git a/tests/test-netflow.c b/tests/test-netflow.c index 76f9baedb..284d7ab4c 100644 --- a/tests/test-netflow.c +++ b/tests/test-netflow.c @@ -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; diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index ebb24c08f..4d73a0dd3 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -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); diff --git a/tests/test-rstp.c b/tests/test-rstp.c index afc5b600d..96c611a33 100644 --- a/tests/test-rstp.c +++ b/tests/test-rstp.c @@ -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, ...) diff --git a/tests/test-sflow.c b/tests/test-sflow.c index b91fd4118..1d512ada1 100644 --- a/tests/test-sflow.c +++ b/tests/test-sflow.c @@ -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; diff --git a/tests/test-stp.c b/tests/test-stp.c index c4e59335e..45f0f4c61 100644 --- a/tests/test-stp.c +++ b/tests/test-stp.c @@ -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, ...) diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index 6c25bfdbf..94a6b90f2 100644 --- a/utilities/ovs-dpctl.c +++ b/utilities/ovs-dpctl.c @@ -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 diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 30cdf99b8..4a9015509 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -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, diff --git a/utilities/ovs-testcontroller.c b/utilities/ovs-testcontroller.c index a615ab49c..4ef7d4bb4 100644 --- a/utilities/ovs-testcontroller.c +++ b/utilities/ovs-testcontroller.c @@ -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[]) diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 5cf12cf66..818184ae3 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -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); diff --git a/vswitchd/ovs-vswitchd.c b/vswitchd/ovs-vswitchd.c index 4d7e4f0fd..b0d08e8af 100644 --- a/vswitchd/ovs-vswitchd.c +++ b/vswitchd/ovs-vswitchd.c @@ -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[]) diff --git a/vswitchd/system-stats.c b/vswitchd/system-stats.c index 778978731..dc0f2c5f9 100644 --- a/vswitchd/system-stats.c +++ b/vswitchd/system-stats.c @@ -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()); diff --git a/vtep/vtep-ctl.c b/vtep/vtep-ctl.c index 357631308..8a1645073 100644 --- a/vtep/vtep-ctl.c +++ b/vtep/vtep-ctl.c @@ -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);