Skip to content

Commit

Permalink
compiler: Define NO_RETURN for MSVC.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
shettyg committed Sep 15, 2014
1 parent d72eff6 commit 270f328
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 46 deletions.
10 changes: 9 additions & 1 deletion lib/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/stream-nossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 10 additions & 10 deletions lib/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
20 changes: 11 additions & 9 deletions lib/vlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *, ...)
Expand Down
2 changes: 1 addition & 1 deletion ovsdb/ovsdb-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ovsdb/ovsdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ovsdb/ovsdb-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/test-jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/test-netflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/test-ovsdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions tests/test-rstp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand Down
2 changes: 1 addition & 1 deletion tests/test-sflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions tests/test-stp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand Down
2 changes: 1 addition & 1 deletion utilities/ovs-dpctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion utilities/ovs-ofctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion utilities/ovs-testcontroller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
Expand Down
6 changes: 3 additions & 3 deletions utilities/ovs-vsctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion vswitchd/ovs-vswitchd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
Expand Down
4 changes: 2 additions & 2 deletions vswitchd/system-stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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'. */
Expand Down Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions vtep/vtep-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 270f328

Please sign in to comment.