From: Jan Kiszka <jan.kiszka@web.de>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Stefan Weil <sw@weilnetz.de>, qemu-devel <qemu-devel@nongnu.org>,
Anthony Liguori <anthony@codemonkey.ws>
Subject: Re: [Qemu-devel] [PATCH] cpu-exec: Fix compiler warning (-Werror=clobbered)
Date: Wed, 18 Sep 2013 09:06:53 +0200 [thread overview]
Message-ID: <5239510D.9070608@web.de> (raw)
In-Reply-To: <CAFEAcA-GzhJUud44EC14zyi0JEwYAer-wHuE9SyE5rzubOUdMA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2349 bytes --]
On 2013-09-17 23:24, Peter Maydell wrote:
> On 17 September 2013 18:03, Stefan Weil <sw@weilnetz.de> wrote:
>> could you please review this patch which removes code added by you earlier?
>> I have run tests with the old code and assertions to see whether the values
>> were really smashed. They never were, and from the documentation of setjmp
>> I'd not expect that they ever might be.
>
> 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)
/* 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 = current_cpu;
+ env = cpu->env_ptr;
if (sigsetjmp(env->jmp_env, 0) == 0) {
/* if an exception is pending, we execute it here */
if (env->exception_index >= 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 = current_cpu;
- env = cpu->env_ptr;
}
} /* for(;;) */
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 263 bytes --]
next prev parent reply other threads:[~2013-09-18 7:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-17 17:03 [Qemu-devel] [PATCH] cpu-exec: Fix compiler warning (-Werror=clobbered) Stefan Weil
2013-09-17 17:17 ` Jan Kiszka
2013-09-17 17:27 ` Stefan Weil
2013-09-17 21:24 ` Peter Maydell
2013-09-18 7:06 ` Jan Kiszka [this message]
2013-09-18 7:26 ` Peter Maydell
2013-09-18 7:48 ` Jan Kiszka
2013-10-28 19:18 ` Stefan Weil
2013-10-29 8:07 ` Jan Kiszka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5239510D.9070608@web.de \
--to=jan.kiszka@web.de \
--cc=anthony@codemonkey.ws \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).