* [PATCH] Aarch64 sim fix for gcc-10 miscompilation.
@ 2021-04-08 1:54 Jim Wilson
2021-04-08 10:36 ` Andrew Burgess
0 siblings, 1 reply; 2+ messages in thread
From: Jim Wilson @ 2021-04-08 1:54 UTC (permalink / raw)
To: gdb-patches
This fixes a problem that occurs when compiled by gcc-10, as the code
is relying on undefined overflow behavior. This is fixed by replacing
compares between 32-bit and 64-bit results with compares that just use
the 64-bit results with a cast.
Tested with the simulator make check and a gcc make check. There were no
regressions.
Committed.
PR sim/27483
* simulator.c (set_flags_for_add32): Compare uresult against
itself. Compare sresult against itself.
---
sim/aarch64/simulator.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sim/aarch64/simulator.c b/sim/aarch64/simulator.c
index 6ba29a0ed57..e0b428d26d9 100644
--- a/sim/aarch64/simulator.c
+++ b/sim/aarch64/simulator.c
@@ -1650,10 +1650,10 @@ set_flags_for_add32 (sim_cpu *cpu, int32_t value1, int32_t value2)
if (result & (1 << 31))
flags |= N;
- if (uresult != (uint32_t)result)
+ if (uresult != (uint32_t)uresult)
flags |= C;
- if (sresult != result)
+ if (sresult != (int32_t)sresult)
flags |= V;
aarch64_set_CPSR (cpu, flags);
--
2.17.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Aarch64 sim fix for gcc-10 miscompilation.
2021-04-08 1:54 [PATCH] Aarch64 sim fix for gcc-10 miscompilation Jim Wilson
@ 2021-04-08 10:36 ` Andrew Burgess
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Burgess @ 2021-04-08 10:36 UTC (permalink / raw)
To: Jim Wilson; +Cc: gdb-patches
* Jim Wilson <jimw@sifive.com> [2021-04-07 18:54:03 -0700]:
> This fixes a problem that occurs when compiled by gcc-10, as the code
> is relying on undefined overflow behavior. This is fixed by replacing
> compares between 32-bit and 64-bit results with compares that just use
> the 64-bit results with a cast.
>
> Tested with the simulator make check and a gcc make check. There were no
> regressions.
>
> Committed.
>
> PR sim/27483
> * simulator.c (set_flags_for_add32): Compare uresult against
> itself. Compare sresult against itself.
LGTM.
Thanks,
Andrew
> ---
> sim/aarch64/simulator.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/sim/aarch64/simulator.c b/sim/aarch64/simulator.c
> index 6ba29a0ed57..e0b428d26d9 100644
> --- a/sim/aarch64/simulator.c
> +++ b/sim/aarch64/simulator.c
> @@ -1650,10 +1650,10 @@ set_flags_for_add32 (sim_cpu *cpu, int32_t value1, int32_t value2)
> if (result & (1 << 31))
> flags |= N;
>
> - if (uresult != (uint32_t)result)
> + if (uresult != (uint32_t)uresult)
> flags |= C;
>
> - if (sresult != result)
> + if (sresult != (int32_t)sresult)
> flags |= V;
>
> aarch64_set_CPSR (cpu, flags);
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-08 10:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08 1:54 [PATCH] Aarch64 sim fix for gcc-10 miscompilation Jim Wilson
2021-04-08 10:36 ` Andrew Burgess
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 read-only IMAP folder(s) and NNTP newsgroup(s).