Add QEMU_NORETURN to some functions
PATCH 1/1 Add QEMU_NORETURN to some functions
Hello,
this patch adds the QEMU_NORETURN attribute to several functions.
Regards
Stefan Weil
Add missing QEMU_NORETURN attribute to several functions. When needed, static is added, too.
bsd-user/qemu.h +1 -1
@@ -136,7 +136,7 @@ abi_long arg5, abi_long arg6);void gemu_log (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); extern THREAD CPUState *thread_env; -void cpu_loop (CPUState *env,enum BSDType bsd_type); +void QEMU_NORETURN cpu_loop(CPUState *env, enum BSDType bsd_type);void init_paths (const char *prefix);const char *path (const char *pathname);char *target_strerror (int err);
darwin-user/main.c +1 -1
@@ -737,7 +737,7 @@ }#endif -void usage (void ) +static void QEMU_NORETURN usage(void) {printf ("qemu-" TARGET_ARCH " version " QEMU_VERSION ", Copyright (c) 2003-2004 Fabrice Bellard\n" "usage: qemu-" TARGET_ARCH " [-h] [-d opts] [-L path] [-s size] program [arguments...]\n"
darwin-user/qemu.h +1 -1
@@ -105,7 +105,7 @@void write_dt (void *ptr,unsigned long addr,unsigned long limit,int flags);extern CPUState *global_env; -void cpu_loop (CPUState *env); +void QEMU_NORETURN cpu_loop(CPUState *env);void init_paths (const char *prefix);const char *path (const char *pathname);
exec-all.h +2 -2
@@ -74,8 +74,8 @@int cpu_restore_state_copy (struct TranslationBlock *tb,CPUState *env,unsigned long searched_pc,void *puc); -void cpu_resume_from_signal (CPUState *env1,void *puc); -void cpu_io_recompile (CPUState *env,void *retaddr); +void QEMU_NORETURN cpu_resume_from_signal(CPUState *env1, void *puc); +void QEMU_NORETURN cpu_io_recompile(CPUState *env, void *retaddr);TranslationBlock *tb_gen_code (CPUState *env,target_ulong pc,target_ulong cs_base,int flags,int cflags);
hw/bt.c +3 -3
@@ -28,7 +28,7 @@ }/* Slaves should never receive these PDUs */ -static void bt_dummy_lmp_connection_complete (struct bt_link_s *link) +static void QEMU_NORETURN bt_dummy_lmp_connection_complete(struct bt_link_s *link) {if (link->slave->reject_reason) fprintf(stderr, "%s: stray LMP_not_accepted received, fixme\n",
@@ -39,13 +39,13 @@exit (-1 ); } -static void bt_dummy_lmp_disconnect_master (struct bt_link_s *link) +static void QEMU_NORETURN bt_dummy_lmp_disconnect_master(struct bt_link_s *link) {fprintf (stderr,"%s: stray LMP_detach received, fixme\n" , __FUNCTION__);exit (-1 ); } -static void bt_dummy_lmp_acl_resp (struct bt_link_s *link, +static void QEMU_NORETURN bt_dummy_lmp_acl_resp(struct bt_link_s *link,const uint8_t *data,int start,int len) {fprintf (stderr,"%s: stray ACL response PDU, fixme\n" , __FUNCTION__);
hw/pxa2xx_dma.c +2 -3
@@ -406,13 +406,12 @@ } } -static uint32_t pxa2xx_dma_readbad (void *opaque,target_phys_addr_t offset) +static uint32_t QEMU_NORETURN pxa2xx_dma_readbad(void *opaque, target_phys_addr_t offset) {cpu_abort (cpu_single_env,"%s: Bad access width\n" , __FUNCTION__); -return 5 ; } -static void pxa2xx_dma_writebad (void *opaque, +static void QEMU_NORETURN pxa2xx_dma_writebad(void *opaque,target_phys_addr_t offset,uint32_t value) {cpu_abort (cpu_single_env,"%s: Bad access width\n" , __FUNCTION__);
linux-user/main.c +1 -1
@@ -2178,7 +2178,7 @@ }#endif /* TARGET_ALPHA */ -static void usage (void ) +static void QEMU_NORETURN usage(void) {printf ("qemu-" TARGET_ARCH " version " QEMU_VERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n" "usage: qemu-" TARGET_ARCH " [options] program [arguments...]\n"
linux-user/qemu.h +1 -1
@@ -174,7 +174,7 @@ abi_long arg5, abi_long arg6);void gemu_log (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); extern THREAD CPUState *thread_env; -void cpu_loop (CPUState *env); +void QEMU_NORETURN cpu_loop(CPUState *env);void init_paths (const char *prefix);const char *path (const char *pathname);char *target_strerror (int err);
linux-user/syscall.c +2 -4
@@ -2861,7 +2861,7 @@sigset_t sigmask; } new_thread_info; -static void *clone_func (void *arg) +static void * QEMU_NORETURN clone_func(void *arg) {new_thread_info *info = arg;CPUState *env;
@@ -2884,19 +2884,17 @@pthread_mutex_unlock (&clone_lock);cpu_loop (env);/* never exits */ - return NULL; }#else /* this stack is the equivalent of the kernel stack associated with a thread/process */ #define NEW_STACK_SIZE 8192 -static int clone_func (void *arg) +static int QEMU_NORETURN clone_func(void *arg) {CPUState *env = arg;cpu_loop (env);/* never exits */ -return 0 ; }#endif
qemu-img.c +1 -1
@@ -51,7 +51,7 @@ }/* Please keep in synch with qemu-img.texi */ -static void help (void ) +static void QEMU_NORETURN help(void) {printf ("qemu-img version " QEMU_VERSION ", Copyright (c) 2004-2008 Fabrice Bellard\n" "usage: qemu-img command [command options]\n"
tap-win32.c +1 -3
@@ -487,7 +487,7 @@return 0 ; } -static DWORD WINAPI tap_win32_thread_entry(LPVOID param) +static DWORD WINAPI QEMU_NORETURN tap_win32_thread_entry(LPVOID param) {tap_win32_overlapped_t *overlapped = (tap_win32_overlapped_t *)param;unsigned long read_size;
@@ -538,8 +538,6 @@ buffer =get_buffer_from_free_list (overlapped); } } - -return 0 ; } static int tap_win32_read(tap_win32_overlapped_t *overlapped,
target-arm/exec.h +1 -1
@@ -55,4 +55,4 @@#include "softmmu_exec.h" #endif -void raise_exception (int ); +void QEMU_NORETURN raise_exception(int);
target-arm/op_helper.c +2 -2
@@ -245,14 +245,14 @@return res; } -void HELPER (wfi )(void ) +void QEMU_NORETURN HELPER(wfi)(void) { env->exception_index =EXCP_HLT ; env->halted =1 ;cpu_loop_exit (); } -void HELPER (exception )(uint32_t excp) +void QEMU_NORETURN HELPER(exception)(uint32_t excp) { env->exception_index = excp;cpu_loop_exit ();
target-i386/op_helper.c +11 -11
@@ -1005,7 +1005,7 @@ #ifdef TARGET_X86_64 #if defined(CONFIG_USER_ONLY) -void helper_syscall(int next_eip_addend) +void QEMU_NORETURN helper_syscall(int next_eip_addend) { env->exception_index = EXCP_SYSCALL; env->exception_next_eip = env->eip + next_eip_addend;
@@ -1898,7 +1898,7 @@ }#endif -void helper_single_step (void ) +void QEMU_NORETURN helper_single_step(void) {#ifndef CONFIG_USER_ONLY check_hw_breakpoints (env,1 );
@@ -2975,7 +2975,7 @@EDX = (uint32_t )(val >>32 ); } -void helper_rdpmc (void ) +void QEMU_NORETURN helper_rdpmc(void) {if ((env->cr[4 ] &CR4_PCE_MASK ) && ((env->hflags &HF_CPL_MASK ) !=0 )) {raise_exception (EXCP0D_GPF );
@@ -4612,7 +4612,7 @@ }#endif -static void do_hlt (void ) +static QEMU_NORETURN void do_hlt(void) { env->hflags &= ~HF_INHIBIT_IRQ_MASK ;/* needed if sti is just before */ env->halted =1 ;
@@ -4620,7 +4620,7 @@cpu_loop_exit (); } -void helper_hlt (int next_eip_addend) +void QEMU_NORETURN helper_hlt(int next_eip_addend) {helper_svm_check_intercept_param (SVM_EXIT_HLT ,0 );EIP += next_eip_addend;
@@ -4652,18 +4652,18 @@ } } -void helper_debug (void ) +void QEMU_NORETURN helper_debug(void) { env->exception_index =EXCP_DEBUG ;cpu_loop_exit (); } -void helper_raise_interrupt (int intno,int next_eip_addend) +void QEMU_NORETURN helper_raise_interrupt(int intno, int next_eip_addend) {raise_interrupt (intno,1 ,0 , next_eip_addend); } -void helper_raise_exception (int exception_index) +void QEMU_NORETURN helper_raise_exception(int exception_index) {raise_exception (exception_index); }
@@ -5036,7 +5036,7 @@ } } -void helper_vmmcall (void ) +void QEMU_NORETURN helper_vmmcall(void) {helper_svm_check_intercept_param (SVM_EXIT_VMMCALL ,0 );raise_exception (EXCP06_ILLOP );
@@ -5124,7 +5124,7 @@ env->hflags2 &= ~HF2_GIF_MASK ; } -void helper_skinit (void ) +void QEMU_NORETURN helper_skinit(void) {helper_svm_check_intercept_param (SVM_EXIT_SKINIT ,0 );/* XXX: not implemented */
@@ -5231,7 +5231,7 @@ }/* Note: currently only 32 bits of exit_code are used */ -void helper_vmexit (uint32_t exit_code,uint64_t exit_info_1) +void QEMU_NORETURN helper_vmexit(uint32_t exit_code, uint64_t exit_info_1) {uint32_t int_ctl;
target-mips/op_helper.c +7 -6
@@ -26,7 +26,7 @@/*****************************************************************************/ /* Exceptions processing helpers */ -void do_raise_exception_err (uint32_t exception,int error_code) +void QEMU_NORETURN do_raise_exception_err (uint32_t exception, int error_code) {#if 1 if (exception <0x100 )
@@ -37,7 +37,7 @@cpu_loop_exit (); } -void do_raise_exception (uint32_t exception) +void QEMU_NORETURN do_raise_exception (uint32_t exception) {do_raise_exception_err (exception,0 ); }
@@ -1830,7 +1830,7 @@ } } -void do_wait (void ) +void QEMU_NORETURN do_wait (void) { env->halted =1 ;do_raise_exception (EXCP_HLT );
@@ -1855,7 +1855,8 @@#define SHIFT 3#include "softmmu_template.h" -static void do_unaligned_access (target_ulong addr,int is_write,int is_user,void *retaddr) +static void QEMU_NORETURN do_unaligned_access (target_ulong addr, int is_write, +int is_user,void *retaddr) { env->CP0_BadVAddr = addr;do_restore_state (retaddr);
@@ -1890,8 +1891,8 @@ env = saved_env; } -void do_unassigned_access (target_phys_addr_t addr,int is_write,int is_exec, -int unused,int size) +void QEMU_NORETURN do_unassigned_access(target_phys_addr_t addr, int is_write, +int is_exec,int unused,int size) {if (is_exec)do_raise_exception (EXCP_IBE );
target-ppc/op_helper.c +2 -2
@@ -38,7 +38,7 @@/*****************************************************************************/ /* Exceptions processing helpers */ -void helper_raise_exception_err (uint32_t exception,uint32_t error_code) +void QEMU_NORETURN helper_raise_exception_err (uint32_t exception, uint32_t error_code) {#if 0 printf ("Raise exception %3x code : %d\n" , exception, error_code);
@@ -48,7 +48,7 @@cpu_loop_exit (); } -void helper_raise_exception (uint32_t exception) +void QEMU_NORETURN helper_raise_exception (uint32_t exception) {helper_raise_exception_err (exception,0 ); }
target-sparc/op_helper.c +5 -5
@@ -49,13 +49,13 @@#endif } -static void raise_exception (int tt) +static void QEMU_NORETURN raise_exception(int tt) { env->exception_index = tt;cpu_loop_exit (); } -void HELPER (raise_exception )(int tt) +void QEMU_NORETURN HELPER(raise_exception)(int tt) {raise_exception (tt); }
@@ -2514,7 +2514,7 @@ }#endif -void helper_debug (void ) +void QEMU_NORETURN helper_debug(void) { env->exception_index =EXCP_DEBUG ;cpu_loop_exit ();
@@ -3036,8 +3036,8 @@ } } -static void do_unaligned_access (target_ulong addr,int is_write,int is_user, -void *retaddr) +static void QEMU_NORETURN do_unaligned_access(target_ulong addr, +int is_write,int is_user,void *retaddr) {#ifdef DEBUG_UNALIGNED printf("Unaligned access to 0x" TARGET_FMT_lx " from 0x" TARGET_FMT_lx
tests/qruncom.c +1 -1
@@ -122,7 +122,7 @@#define COM_BASE_ADDR 0x10100 -void usage (void ) +static void QEMU_NORETURN usage(void) {printf ("qruncom version 0.1 (c) 2003 Fabrice Bellard\n" "usage: qruncom file.com\n"
tests/runcom.c +1 -1
@@ -25,7 +25,7 @@#define COM_BASE_ADDR 0x10100 -void usage (void ) +static void QEMU_NORETURN usage(void) {printf ("runcom version 0.1 (c) 2003 Fabrice Bellard\n" "usage: runcom file.com\n"
Quoted 4 lines · Stefan Weil
Hello,
this patch adds the
QEMU_NORETURNattribute to several functions.
Why? Does this eliminate warnings?
Regards,
Anthony Liguori
Quoted 5 lines
Regards
Stefan Weil
Quoted 4 lines · Stefan Weil
Hello,
this patch adds the
QEMU_NORETURNattribute to several functions.
Based on some IRC discussion, the best place to use QEMU_NORETURN is in header files. If you add it to a C file, you don't really need it (since the compiler can determine this anyway).
Regards,
Anthony Liguori
Quoted 5 lines
Regards
Stefan Weil
Quoted 11 lines · Anthony Liguori
Quoted 4 lines · Stefan Weil
Hello,
this patch adds the
QEMU_NORETURNattribute to several functions.Why? Does this eliminate warnings?
Regards,
Anthony Liguori
Yes, if you compile using compiler option -Wmissing-noreturn.
Regards
Stefan Weil
Quoted 6 lines · Anthony Liguori
Quoted 4 lines · Stefan Weil
Hello,
this patch adds the
QEMU_NORETURNattribute to several functions.
Quoted 7 lines
Based on some IRC discussion, the best place to use
QEMU_NORETURNis in header files. If you add it to a C file, you don't really need it (since the compiler can determine this anyway).Regards,
Anthony Liguori
This is correct - in theory. I have put all QEMU_NORETURN in header files were possible.
In practice, there remain two cases which are exceptions to the rule:
Without the attribute, gcc will give warnings (when they are enabled) for static functions
which don't return. It could determine this automatically, but it does not.
And for some helper functions, there are no simple prototypes in header files because
they are built by compiler macros, so it is difficult to add the attribute in the header.
If we want to allow -Wmissing-noreturn some day (which is needed to see the interesting functions), I think we have to accept these two exceptions.
Regards
Stefan Weil
Quoted 3 lines · Stefan Weil
Without the attribute, gcc will give warnings (when they are enabled) for static functions which don't return. It could determine this automatically, but it does not.
Obviously it can determine it automatically, otherwise it couldn't warn :-)
-- Jamie
Quoted 8 lines · Anthony Liguori
Quoted 1 line · Stefan Weil
Would a patch which only adds noreturn to header files be accepted?
Yup.
Regards,
Anthony Liguori
Here is an extract of my previous patch.
This new patch adds the noreturn attribute only to global functions declared in header files.
Regards
Stefan Weil
Add missing QEMU_NORETURN attribute to several global functions.
bsd-user/qemu.h +1 -1
@@ -136,7 +136,7 @@ abi_long arg5, abi_long arg6);void gemu_log (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); extern THREAD CPUState *thread_env; -void cpu_loop (CPUState *env,enum BSDType bsd_type); +void QEMU_NORETURN cpu_loop(CPUState *env, enum BSDType bsd_type);void init_paths (const char *prefix);const char *path (const char *pathname);char *target_strerror (int err);
darwin-user/qemu.h +1 -1
@@ -105,7 +105,7 @@void write_dt (void *ptr,unsigned long addr,unsigned long limit,int flags);extern CPUState *global_env; -void cpu_loop (CPUState *env); +void QEMU_NORETURN cpu_loop(CPUState *env);void init_paths (const char *prefix);const char *path (const char *pathname);
exec-all.h +2 -2
@@ -74,8 +74,8 @@int cpu_restore_state_copy (struct TranslationBlock *tb,CPUState *env,unsigned long searched_pc,void *puc); -void cpu_resume_from_signal (CPUState *env1,void *puc); -void cpu_io_recompile (CPUState *env,void *retaddr); +void QEMU_NORETURN cpu_resume_from_signal(CPUState *env1, void *puc); +void QEMU_NORETURN cpu_io_recompile(CPUState *env, void *retaddr);TranslationBlock *tb_gen_code (CPUState *env,target_ulong pc,target_ulong cs_base,int flags,int cflags);
linux-user/qemu.h +1 -1
@@ -174,7 +174,7 @@ abi_long arg5, abi_long arg6);void gemu_log (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); extern THREAD CPUState *thread_env; -void cpu_loop (CPUState *env); +void QEMU_NORETURN cpu_loop(CPUState *env);void init_paths (const char *prefix);const char *path (const char *pathname);char *target_strerror (int err);
target-arm/exec.h +1 -1
@@ -55,4 +55,4 @@#include "softmmu_exec.h" #endif -void raise_exception (int ); +void QEMU_NORETURN raise_exception(int);