Skip to contentSkip to conversation

fix a few clang warnings

PATCH In review Paolo Bonzini 4 participants 15 messages Jan 26, 2010 – Jan 31, 2010

lore
Share & tools
lore
#0 lore raw

cover fix a few clang warnings

All of these should be quite uncontroversial. The vnc.c change is not what you'd expect though (could be a real bug, so I leave the clang warning).

I'll propose the second patch for 0.12 after a short while.

Paolo Bonzini (6):
remove two dead assignments in target-i386/translate.c fix undefined shifts by >32
exec.c: dead assignments
vnc.c: warn about ignored option
usb-linux.c: remove write-only variable
fix audio_bug related failures

 audio/audio.c           |   44 ++++++++++++++++++++------------------------
 audio/audio_int.h       |    3 ++-
 exec.c                  |    4 ----
 target-i386/translate.c |    2 --
 usb-linux.c             |    2 --
 vl.c                    |    4 ++--
 vnc.c                   |    1 +
 7 files changed, 25 insertions(+), 35 deletions(-)
#1 lore raw

PATCH 1/6 remove two dead assignments in target-i386/translate.c

---
 target-i386/translate.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
target-i386/translate.c +0 -2
index 8078112..a597e80 100644
@@ -4692,8 +4692,6 @@ static target_ulong disas_insn(DisasContext *s, target_ulong pc_start)
             ot = dflag + OT_WORD;
 
         modrm = ldub_code(s->pc++);
-        mod = (modrm >> 6) & 3;
-        rm = (modrm & 7) | REX_B(s);
         reg = ((modrm >> 3) & 7) | rex_r;
 
         gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0);
Signature · 1 line
1.6.6
#2 lore raw

PATCH 2/6 fix undefined shifts by >32

In reply to Paolo Bonzini
---
 vl.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
vl.c +2 -2
index 5e8c775..d9f1ccb 100644
@@ -2373,9 +2373,9 @@ static void numa_add(const char *optarg)
                         fprintf(stderr,
                             "only 63 CPUs in NUMA mode supported.\n");
                     }
-                    value = (1 << (endvalue + 1)) - (1 << value);
+                    value = (2ULL << endvalue) - (1ULL << value);
                 } else {
-                    value = 1 << value;
+                    value = 1ULL << value;
                 }
             }
             node_cpumask[nodenr] = value;
Signature · 1 line
1.6.6
#3 lore raw

PATCH 3/6 exec.c: dead assignments

In reply to Paolo Bonzini
---
 exec.c |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)
exec.c +0 -4
index 1190591..64109a7 100644
@@ -2489,17 +2489,13 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
 ram_addr_t qemu_ram_addr_from_host(void *ptr)
 {
     RAMBlock *prev;
-    RAMBlock **prevp;
     RAMBlock *block;
     uint8_t *host = ptr;
 
     prev = NULL;
-    prevp = &ram_blocks;
     block = ram_blocks;
     while (block && (block->host > host
                      || block->host + block->length <= host)) {
-        if (prev)
-          prevp = &prev->next;
         prev = block;
         block = block->next;
     }
Signature · 1 line
1.6.6
#4 lore raw

PATCH 4/6 vnc.c: warn about ignored option

In reply to Paolo Bonzini
---
 vnc.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
vnc.c +1 -0
index cc2a26e..9ebee09 100644
@@ -2563,6 +2563,7 @@ int vnc_display_open(DisplayState *ds, const char *display)
             reverse = 1;
         } else if (strncmp(options, "to=", 3) == 0) {
             to_port = atoi(options+3) + 5900;
+            fprintf(stderr, "qemu: warning: to= option for -vnc ignored\n");
 #ifdef CONFIG_VNC_SASL
         } else if (strncmp(options, "sasl", 4) == 0) {
             sasl = 1; /* Require SASL auth */
Signature · 1 line
1.6.6
#5 lore raw

Re: [Qemu-devel] [PATCH 4/6] vnc.c: warn about ignored option

Quoted 10 lines · Paolo Bonzini
---
  vnc.c |    1 +
  1 files changed, 1 insertions(+), 0 deletions(-)
vnc.c +0 -0
index cc2a26e..9ebee09 100644

vnc.c int vnc_display_open(DisplayState *ds, const char *display) · line 2567

Quoted 5 lines
vnc.c +1 -0
@@ -2563,6 +2563,7 @@ int vnc_display_open(DisplayState *ds, const char *display)
              reverse = 1;
          } else if (strncmp(options, "to=", 3) == 0) {
              to_port = atoi(options+3) + 5900;
+            fprintf(stderr, "qemu: warning: to= option for -vnc ignored\n");
 

If we're ignoring it, why even have the code? How did clang spot this?

Regards,

Anthony Liguori

#6 lore raw

Re: [Qemu-devel] [PATCH 4/6] vnc.c: warn about ignored option

Quoted 6 lines · Anthony Liguori
Quoted 5 lines · Paolo Bonzini

---
vnc.c | 1 +

1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 12 lines

vnc.c int vnc_display_open(DisplayState *ds, const · line 2567

Quoted 10 lines
vnc.c +1 -0
index cc2a26e..9ebee09 100644
@@ -2563,6 +2563,7 @@ int vnc_display_open(DisplayState *ds, const
 char *display)
 reverse = 1;
 } else if (strncmp(options, "to=", 3) == 0) {
 to_port = atoi(options+3) + 5900;
+ fprintf(stderr, "qemu: warning: to= option for -vnc ignored\n");

If we're ignoring it, why even have the code? How did clang spot this?

to= isn't ignored. The to= handling has been moved to qemu-socket.c though a while ago. So clang spotted correctly that to_port variable is unused. The whole 'if (...) {}' is a leftover which can go away now.

cheers,
Gerd

#7 lore raw

PATCH 5/6 usb-linux.c: remove write-only variable

In reply to Paolo Bonzini
---
 usb-linux.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
usb-linux.c +0 -2
index 1aaa595..ba8facf 100644
@@ -1007,11 +1007,9 @@ USBDevice *usb_host_device_open(const char *devname)
 {
     struct USBAutoFilter filter;
     USBDevice *dev;
-    USBHostDevice *s;
     char *p;
 
     dev = usb_create(NULL /* FIXME */, "usb-host");
-    s = DO_UPCAST(USBHostDevice, dev, dev);
 
     if (strstr(devname, "auto:")) {
         if (parse_filter(devname, &filter) < 0)
Signature · 1 line
1.6.6
#8 lore raw

PATCH 6/6 fix audio_bug related failures

In reply to Paolo Bonzini
---
 audio/audio.c     |   44 ++++++++++++++++++++------------------------
 audio/audio_int.h |    3 ++-
 2 files changed, 22 insertions(+), 25 deletions(-)
audio/audio.c +20 -24
index 2a20e5b..7fce46c 100644
@@ -118,42 +118,38 @@ struct mixeng_volume nominal_volume = {
 static void audio_print_options (const char *prefix,
                                  struct audio_option *opt);
 
-int audio_bug (const char *funcname, int cond)
+void audio_bug_found (const char *funcname)
 {
-    if (cond) {
-        static int shown;
-
-        AUD_log (NULL, "A bug was just triggered in %s\n", funcname);
-        if (!shown) {
-            struct audio_driver *d;
-
-            shown = 1;
-            AUD_log (NULL, "Save all your work and restart without audio\n");
-            AUD_log (NULL, "Please send bug report to [email protected]\n");
-            AUD_log (NULL, "I am sorry\n");
-            d = glob_audio_state.drv;
-            if (d) {
-                audio_print_options (d->name, d->options);
-            }
+    static int shown;
+
+    AUD_log (NULL, "A bug was just triggered in %s\n", funcname);
+    if (!shown) {
+        struct audio_driver *d;
+
+        shown = 1;
+        AUD_log (NULL, "Save all your work and restart without audio\n");
+        AUD_log (NULL, "Please send bug report to [email protected]\n");
+        AUD_log (NULL, "I am sorry\n");
+        d = glob_audio_state.drv;
+        if (d) {
+            audio_print_options (d->name, d->options);
         }
-        AUD_log (NULL, "Context:\n");
+    }
+    AUD_log (NULL, "Context:\n");
 
 #if defined AUDIO_BREAKPOINT_ON_BUG
 #  if defined HOST_I386
 #    if defined __GNUC__
-        __asm__ ("int3");
+    __asm__ ("int3");
 #    elif defined _MSC_VER
-        _asm _emit 0xcc;
+    _asm _emit 0xcc;
 #    else
-        abort ();
+    abort ();
 #    endif
 #  else
-        abort ();
+    abort ();
 #  endif
 #endif
-    }
-
-    return cond;
 }
 #endif
 
audio/audio_int.h +2 -1
index 06e313f..4244615 100644
@@ -223,7 +223,8 @@ int  audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
 int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
                            int live, int pending);
 
-int audio_bug (const char *funcname, int cond);
+#define audio_bug(funcname, cond) ((cond) ? audio_bug_found (funcname), 1 : 0)
+void audio_bug_found (const char *funcname);
 void *audio_calloc (const char *funcname, int nmemb, size_t size);
 
 void audio_run (const char *msg);
Signature · 1 line
1.6.6
#9 lore raw

Re: [Qemu-devel] [PATCH 6/6] fix audio_bug related failures

What did clang complain about? It's not obvious to me.

Regards,

Anthony Liguori

Quoted 88 lines · Paolo Bonzini
---
  audio/audio.c     |   44 ++++++++++++++++++++------------------------
  audio/audio_int.h |    3 ++-
  2 files changed, 22 insertions(+), 25 deletions(-)
audio/audio.c +20 -24
index 2a20e5b..7fce46c 100644
@@ -118,42 +118,38 @@ struct mixeng_volume nominal_volume = {
  static void audio_print_options (const char *prefix,
                                   struct audio_option *opt);
 
-int audio_bug (const char *funcname, int cond)
+void audio_bug_found (const char *funcname)
  {
-    if (cond) {
-        static int shown;
-
-        AUD_log (NULL, "A bug was just triggered in %s\n", funcname);
-        if (!shown) {
-            struct audio_driver *d;
-
-            shown = 1;
-            AUD_log (NULL, "Save all your work and restart without audio\n");
-            AUD_log (NULL, "Please send bug report to [email protected]\n");
-            AUD_log (NULL, "I am sorry\n");
-            d = glob_audio_state.drv;
-            if (d) {
-                audio_print_options (d->name, d->options);
-            }
+    static int shown;
+
+    AUD_log (NULL, "A bug was just triggered in %s\n", funcname);
+    if (!shown) {
+        struct audio_driver *d;
+
+        shown = 1;
+        AUD_log (NULL, "Save all your work and restart without audio\n");
+        AUD_log (NULL, "Please send bug report to [email protected]\n");
+        AUD_log (NULL, "I am sorry\n");
+        d = glob_audio_state.drv;
+        if (d) {
+            audio_print_options (d->name, d->options);
          }
-        AUD_log (NULL, "Context:\n");
+    }
+    AUD_log (NULL, "Context:\n");
 
  #if defined AUDIO_BREAKPOINT_ON_BUG
  #  if defined HOST_I386
  #    if defined __GNUC__
-        __asm__ ("int3");
+    __asm__ ("int3");
  #    elif defined _MSC_VER
-        _asm _emit 0xcc;
+    _asm _emit 0xcc;
  #    else
-        abort ();
+    abort ();
  #    endif
  #  else
-        abort ();
+    abort ();
  #  endif
  #endif
-    }
-
-    return cond;
  }
  #endif
 
audio/audio_int.h +2 -1
index 06e313f..4244615 100644
@@ -223,7 +223,8 @@ int  audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
  int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
                             int live, int pending);
 
-int audio_bug (const char *funcname, int cond);
+#define audio_bug(funcname, cond) ((cond) ? audio_bug_found (funcname), 1 : 0)
+void audio_bug_found (const char *funcname);
  void *audio_calloc (const char *funcname, int nmemb, size_t size);
 
  void audio_run (const char *msg);
#10 lore raw

[Qemu-devel] Re: [PATCH 6/6] fix audio_bug related failures

Quoted 1 line · Anthony Liguori

What did clang complain about? It's not obvious to me.

It doesn't see that audio_bug returns cond, and gives quite a few false positive in its callers.

Paolo

#11 lore raw

Re: [Qemu-devel] Re: [PATCH 6/6] fix audio_bug related failures

Quoted 4 lines · Paolo Bonzini
Quoted 1 line · Anthony Liguori

What did clang complain about? It's not obvious to me.

It doesn't see that audio_bug returns cond, and gives quite a few false positive in its callers.

Ah, this is a clang issue. I'll have to defer to malc on this one.

Regards,

Anthony Liguori

Quoted 5 lines

Paolo

#12 lore raw

Re: [Qemu-devel] Re: [PATCH 6/6] fix audio_bug related failures

Quoted 9 lines · Anthony Liguori
Quoted 5 lines · Paolo Bonzini
Quoted 1 line · Anthony Liguori

What did clang complain about? It's not obvious to me.

It doesn't see that audio_bug returns cond, and gives quite a few false positive in its callers.

Ah, this is a clang issue. I'll have to defer to malc on this one.

I'm against it.

Signature · 1 line
mailto:[email protected]
#13 lore raw

[Qemu-devel] Re: [PATCH 6/6] fix audio_bug related failures

Quoted 4 lines · malc
Quoted 2 lines · Anthony Liguori
Quoted 1 line · Paolo Bonzini

On 01/27/2010 03:10 AM, Anthony Liguori wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

What did clang complain about? It's not obvious to me.

It doesn't see that audio_bug returns cond, and gives quite a few false positive in its callers.

Ah, this is a clang issue. I'll have to defer to malc on this one.

I'm against it.

Ok, I'll withdraw this patch. I already posted v2.

Paolo

#14 lore raw
In reply to Paolo Bonzini
Quoted 4 lines · Paolo Bonzini

All of these should be quite uncontroversial. The vnc.c change is not what you'd expect though (could be a real bug, so I leave the clang warning).

I'm scratching my head quite a bit on these. Can you resend the series with commit messages that actually explain what the problem clang is reporting and why it fixes it.

The vnc one is just whacky.

Regards,

Anthony Liguori