From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMBr4-0003eU-T4 for qemu-devel@nongnu.org; Wed, 18 Sep 2013 03:07:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VMBqy-0008Vw-QV for qemu-devel@nongnu.org; Wed, 18 Sep 2013 03:07:18 -0400 Received: from mout.web.de ([212.227.15.3]:51284) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMBqy-0008Uc-GX for qemu-devel@nongnu.org; Wed, 18 Sep 2013 03:07:12 -0400 Received: from mchn199C.mchp.siemens.de ([95.157.58.223]) by smtp.web.de (mrweb002) with ESMTPSA (Nemesis) id 0Lk8T4-1Vtt2a49Ig-00c7VB for ; Wed, 18 Sep 2013 09:07:11 +0200 Message-ID: <5239510D.9070608@web.de> Date: Wed, 18 Sep 2013 09:06:53 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <1379437402-30804-1-git-send-email-sw@weilnetz.de> In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="tvb1bHquW0hVhAqONI0wPTXHeEFw4DJ6O" Subject: Re: [Qemu-devel] [PATCH] cpu-exec: Fix compiler warning (-Werror=clobbered) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Stefan Weil , qemu-devel , Anthony Liguori This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --tvb1bHquW0hVhAqONI0wPTXHeEFw4DJ6O Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 2013-09-17 23:24, Peter Maydell wrote: > On 17 September 2013 18:03, Stefan Weil wrote: >> could you please review this patch which removes code added by you ear= lier? >> I have run tests with the old code and assertions to see whether the v= alues >> were really smashed. They never were, and from the documentation of se= tjmp >> I'd not expect that they ever might be. >=20 > We had a discussion about this back in 2011. Any compiler which needs > these statements is definitely buggy -- the C standard mandates that > they're not needed. I'm not that sure about this. We have a no-return function involved between setjmp and the actual longjmp. Why should the compiler have to preserve local variables when entering cpu_loop_exit? > Unfortunately Jan never said what compiler he was using; If you look down the thread: gcc 4.5.0. However, gcc 4.5.1 does not seem to reproduce the issue anymore. On the other hand, reloading that variable outside the setjmp/longjmp section should not make the compiler worry about clobbering. The warning seems false positive: if you pull the assignment before the setjmp (see below), it's fine, if you move it at the end of the very same loop, my compiler starts to grumble. diff --git a/cpu-exec.c b/cpu-exec.c index 5a43995..3882d74 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -266,6 +266,10 @@ int cpu_exec(CPUArchState *env) =20 /* prepare setjmp context for exception handling */ for(;;) { + /* Reload env after longjmp - the compiler may have smashed all + * local variables as cpu_loop_exit is marked 'noreturn'. */ + cpu =3D current_cpu; + env =3D cpu->env_ptr; if (sigsetjmp(env->jmp_env, 0) =3D=3D 0) { /* if an exception is pending, we execute it here */ if (env->exception_index >=3D 0) { @@ -676,11 +680,6 @@ int cpu_exec(CPUArchState *env) /* reset soft MMU for next block (it can currently 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'. */ - cpu =3D current_cpu; - env =3D cpu->env_ptr; } } /* for(;;) */ =20 Jan --tvb1bHquW0hVhAqONI0wPTXHeEFw4DJ6O Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlI5URQACgkQitSsb3rl5xTiCQCgzuv9RpqLKltESmaiYDv8ueS8 lEwAniaaxwqCgVarOtn10fjgOoqU6I3G =pOqq -----END PGP SIGNATURE----- --tvb1bHquW0hVhAqONI0wPTXHeEFw4DJ6O--