diff options
author | Gurucharan Shetty <gshetty@nicira.com> | 2014-09-15 12:58:09 -0700 |
---|---|---|
committer | Gurucharan Shetty <gshetty@nicira.com> | 2014-09-15 15:15:35 -0700 |
commit | 270f328621bfd8f80659150d5d3eec51754b5bfb (patch) | |
tree | c068c18ce82dcee21750e55f61ee2b3e4e157064 /lib | |
parent | d72eff6cec01187d9b6b0f8befdbdec0943e6012 (diff) | |
download | openvswitch-270f328621bfd8f80659150d5d3eec51754b5bfb.tar.gz |
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 <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compiler.h | 10 | ||||
-rw-r--r-- | lib/stream-nossl.c | 2 | ||||
-rw-r--r-- | lib/util.h | 20 | ||||
-rw-r--r-- | lib/vlog.h | 20 |
4 files changed, 31 insertions, 21 deletions
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 *, ...) |