qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv3] exynos4210_gic: Suppress gcc9 format-truncation warnings
@ 2019-12-02  6:08 David Gibson
  2019-12-02 16:08 ` Richard Henderson
  0 siblings, 1 reply; 4+ messages in thread
From: David Gibson @ 2019-12-02  6:08 UTC (permalink / raw)
  To: peter.maydell
  Cc: i.mitsyanko, richard.henderson, qemu-devel, qemu-arm,
	Philippe Mathieu-Daudé,
	David Gibson

exynos4210_gic_realize() prints the number of cpus into some temporary
buffers, but it only allows 3 bytes space for it.  That's plenty:
existing machines will only ever set this value to EXYNOS4210_NCPUS
(2).  But the compiler can't always figure that out, so some[*] gcc9
versions emit -Wformat-truncation warnings.

We can fix that by hinting the constraint to the compiler with a
suitably placed assert().

[*] The bizarre thing here, is that I've long gotten these warnings
    compiling in a 32-bit x86 container as host - Fedora 30 with
    gcc-9.2.1-1.fc30.i686 - but it compiles just fine on my normal
    x86_64 host - Fedora 30 with and gcc-9.2.1-1.fc30.x86_64.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Peter, up to you if you squeeze this in for qemu-4.2 or leave it until 5.0

Changes since v2:
 * Moved the assert outside the for loop using a trick suggested by
   Richard Henderson
Changes since v1:
 * Used an assert to hint the compiler, instead of increasing the
   buffer size.

---
 hw/intc/exynos4210_gic.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/hw/intc/exynos4210_gic.c b/hw/intc/exynos4210_gic.c
index a1b699b6ba..ddd006aca6 100644
--- a/hw/intc/exynos4210_gic.c
+++ b/hw/intc/exynos4210_gic.c
@@ -293,6 +293,7 @@ static void exynos4210_gic_realize(DeviceState *dev, Error **errp)
     char cpu_alias_name[sizeof(cpu_prefix) + 3];
     char dist_alias_name[sizeof(cpu_prefix) + 3];
     SysBusDevice *gicbusdev;
+    uint32_t n = s->num_cpu;
     uint32_t i;
 
     s->gic = qdev_create(NULL, "arm_gic");
@@ -313,7 +314,14 @@ static void exynos4210_gic_realize(DeviceState *dev, Error **errp)
     memory_region_init(&s->dist_container, obj, "exynos4210-dist-container",
             EXYNOS4210_EXT_GIC_DIST_REGION_SIZE);
 
-    for (i = 0; i < s->num_cpu; i++) {
+    /*
+     * This clues in gcc that our on-stack buffers do, in fact have
+     * enough room for the cpu numbers.  gcc 9.2.1 on 32-bit x86
+     * doesn't figure this out, otherwise and gives spurious warnings.
+     */
+    assert(n <= EXYNOS4210_NCPUS);
+    for (i = 0; i < n; i++) {
+
         /* Map CPU interface per SMP Core */
         sprintf(cpu_alias_name, "%s%x", cpu_prefix, i);
         memory_region_init_alias(&s->cpu_alias[i], obj,
-- 
2.23.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCHv3] exynos4210_gic: Suppress gcc9 format-truncation warnings
  2019-12-02  6:08 [PATCHv3] exynos4210_gic: Suppress gcc9 format-truncation warnings David Gibson
@ 2019-12-02 16:08 ` Richard Henderson
  2019-12-02 17:44   ` Peter Maydell
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Henderson @ 2019-12-02 16:08 UTC (permalink / raw)
  To: David Gibson, peter.maydell
  Cc: i.mitsyanko, qemu-arm, Philippe Mathieu-Daudé, qemu-devel

On 12/1/19 6:08 AM, David Gibson wrote:
>  
> -    for (i = 0; i < s->num_cpu; i++) {
> +    /*
> +     * This clues in gcc that our on-stack buffers do, in fact have
> +     * enough room for the cpu numbers.  gcc 9.2.1 on 32-bit x86
> +     * doesn't figure this out, otherwise and gives spurious warnings.
> +     */
> +    assert(n <= EXYNOS4210_NCPUS);
> +    for (i = 0; i < n; i++) {
> +
>          /* Map CPU interface per SMP Core */

Watch out for the extra line added at the start of the block.  Otherwise,

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv3] exynos4210_gic: Suppress gcc9 format-truncation warnings
  2019-12-02 16:08 ` Richard Henderson
@ 2019-12-02 17:44   ` Peter Maydell
  2019-12-03  0:21     ` David Gibson
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2019-12-02 17:44 UTC (permalink / raw)
  To: Richard Henderson
  Cc: Igor Mitsyanko, qemu-arm, Philippe Mathieu-Daudé,
	QEMU Developers, David Gibson

On Mon, 2 Dec 2019 at 16:08, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 12/1/19 6:08 AM, David Gibson wrote:
> >
> > -    for (i = 0; i < s->num_cpu; i++) {
> > +    /*
> > +     * This clues in gcc that our on-stack buffers do, in fact have
> > +     * enough room for the cpu numbers.  gcc 9.2.1 on 32-bit x86
> > +     * doesn't figure this out, otherwise and gives spurious warnings.
> > +     */
> > +    assert(n <= EXYNOS4210_NCPUS);
> > +    for (i = 0; i < n; i++) {
> > +
> >          /* Map CPU interface per SMP Core */
>
> Watch out for the extra line added at the start of the block.  Otherwise,
>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

I thought about putting this in rc4 but eventually decided
against it. Queued for 5.0 (with the stray extra blank line removed).

thanks
-- PMM


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv3] exynos4210_gic: Suppress gcc9 format-truncation warnings
  2019-12-02 17:44   ` Peter Maydell
@ 2019-12-03  0:21     ` David Gibson
  0 siblings, 0 replies; 4+ messages in thread
From: David Gibson @ 2019-12-03  0:21 UTC (permalink / raw)
  To: Peter Maydell
  Cc: Igor Mitsyanko, Philippe Mathieu-Daudé,
	qemu-arm, Richard Henderson, QEMU Developers

[-- Attachment #1: Type: text/plain, Size: 1165 bytes --]

On Mon, Dec 02, 2019 at 05:44:11PM +0000, Peter Maydell wrote:
> On Mon, 2 Dec 2019 at 16:08, Richard Henderson
> <richard.henderson@linaro.org> wrote:
> >
> > On 12/1/19 6:08 AM, David Gibson wrote:
> > >
> > > -    for (i = 0; i < s->num_cpu; i++) {
> > > +    /*
> > > +     * This clues in gcc that our on-stack buffers do, in fact have
> > > +     * enough room for the cpu numbers.  gcc 9.2.1 on 32-bit x86
> > > +     * doesn't figure this out, otherwise and gives spurious warnings.
> > > +     */
> > > +    assert(n <= EXYNOS4210_NCPUS);
> > > +    for (i = 0; i < n; i++) {
> > > +
> > >          /* Map CPU interface per SMP Core */
> >
> > Watch out for the extra line added at the start of the block.  Otherwise,
> >
> > Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> 
> I thought about putting this in rc4 but eventually decided
> against it. Queued for 5.0 (with the stray extra blank line
> removed).

Great!

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-03  0:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-02  6:08 [PATCHv3] exynos4210_gic: Suppress gcc9 format-truncation warnings David Gibson
2019-12-02 16:08 ` Richard Henderson
2019-12-02 17:44   ` Peter Maydell
2019-12-03  0:21     ` David Gibson

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).