From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zu0lt-0003wx-Ew for qemu-devel@nongnu.org; Wed, 04 Nov 2015 11:18:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zu0lr-0002OL-Gx for qemu-devel@nongnu.org; Wed, 04 Nov 2015 11:18:49 -0500 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:38583) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zu0lr-0002OG-AF for qemu-devel@nongnu.org; Wed, 04 Nov 2015 11:18:47 -0500 Received: by wicll6 with SMTP id ll6so35320645wic.1 for ; Wed, 04 Nov 2015 08:18:46 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 4 Nov 2015 17:18:28 +0100 Message-Id: <1446653912-116150-11-git-send-email-pbonzini@redhat.com> In-Reply-To: <1446653912-116150-1-git-send-email-pbonzini@redhat.com> References: <1446653912-116150-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PULL 10/14] cpu-exec: Fix compiler warning (-Werror=clobbered) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Weil From: Stefan Weil Reloading of local variables after sigsetjmp is only needed for some buggy compilers. The code which should reload these variables causes compiler warnings with gcc 4.7 when compiler optimizations are enabled: cpu-exec.c:204:15: error: variable ‘cpu’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered] cpu-exec.c:207:15: error: variable ‘cc’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered] cpu-exec.c:202:28: error: argument ‘env’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered] Now this code is only used for compilers which need it (and gcc 4.5.x, x > 0 which does not need it but won't give warnings). There were bug reports for clang and gcc 4.5.0, while gcc 4.5.1 was reported to work fine without the reload code. For clang it is not clear which versions are affected, so simply keep the status quo for all clang compilations. This can be improved later. Signed-off-by: Stefan Weil Message-Id: <1443266606-21400-1-git-send-email-sw@weilnetz.de> Signed-off-by: Paolo Bonzini --- cpu-exec.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index 7eef083..2cfb3d0 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -539,15 +539,27 @@ int cpu_exec(CPUState *cpu) only be set by a memory fault) */ } /* for(;;) */ } else { - /* Reload env after longjmp - the compiler may have smashed all - * local variables as longjmp is marked 'noreturn'. */ +#if defined(__clang__) || !QEMU_GNUC_PREREQ(4, 6) + /* Some compilers wrongly smash all local variables after + * siglongjmp. There were bug reports for gcc 4.5.0 and clang. + * Reload essential local variables here for those compilers. + * Newer versions of gcc would complain about this code (-Wclobbered). */ cpu = current_cpu; cc = CPU_GET_CLASS(cpu); - cpu->can_do_io = 1; #ifdef TARGET_I386 x86_cpu = X86_CPU(cpu); env = &x86_cpu->env; #endif +#else /* buggy compiler */ + /* Assert that the compiler does not smash local variables. */ + g_assert(cpu == current_cpu); + g_assert(cc == CPU_GET_CLASS(cpu)); +#ifdef TARGET_I386 + g_assert(x86_cpu == X86_CPU(cpu)); + g_assert(env == &x86_cpu->env); +#endif +#endif /* buggy compiler */ + cpu->can_do_io = 1; tb_lock_reset(); } } /* for(;;) */ -- 1.8.3.1