Skip to contentSkip to conversation

es1370: Fix compiler warnings for debug code

PATCH Superseded Stefan Weil 3 participants 7 messages Sep 30, 2010 – Oct 2, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 es1370: Fix compiler warnings for debug code

The patch fixes these gcc warnings:

./hw/es1370.c: In function ‘es1370_update_voices’:
./hw/es1370.c:411: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’ ./hw/es1370.c: In function ‘es1370_writel’:
./hw/es1370.c:579: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c:589: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c:606: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c: In function ‘es1370_readl’:
./hw/es1370.c:748: error: suggest braces around empty body in an ‘if’ statement

---
 hw/es1370.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
hw/es1370.c +6 -5
index 40cb48c..c87bbf2 100644
@@ -408,7 +408,7 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl)
 
         if ((old_fmt != new_fmt) || (old_freq != new_freq)) {
             d->shift = (new_fmt & 1) + (new_fmt >> 1);
-            ldebug ("channel %d, freq = %d, nchannels %d, fmt %d, shift %d\n",
+            ldebug ("channel %zu, freq = %d, nchannels %d, fmt %d, shift %d\n",
                     i,
                     new_freq,
                     1 << (new_fmt & 1),
@@ -576,7 +576,7 @@ IO_WRITE_PROTO (es1370_writel)
         d++;
     case ES1370_REG_DAC1_SCOUNT:
         d->scount = (val & 0xffff) | (d->scount & ~0xffff);
-        ldebug ("chan %d CURR_SAMP_CT %d, SAMP_CT %d\n",
+        ldebug ("chan %ld CURR_SAMP_CT %d, SAMP_CT %d\n",
                 d - &s->chan[0], val >> 16, (val & 0xffff));
         break;
 
@@ -586,7 +586,7 @@ IO_WRITE_PROTO (es1370_writel)
         d++;
     case ES1370_REG_DAC1_FRAMEADR:
         d->frame_addr = val;
-        ldebug ("chan %d frame address %#x\n", d - &s->chan[0], val);
+        ldebug ("chan %ld frame address %#x\n", d - &s->chan[0], val);
         break;
 
     case ES1370_REG_PHANTOM_FRAMECNT:
@@ -603,7 +603,7 @@ IO_WRITE_PROTO (es1370_writel)
     case ES1370_REG_DAC1_FRAMECNT:
         d->frame_cnt = val;
         d->leftover = 0;
-        ldebug ("chan %d frame count %d, buffer size %d\n",
+        ldebug ("chan %ld frame count %d, buffer size %d\n",
                 d - &s->chan[0], val >> 16, val & 0xffff);
         break;
 
@@ -743,9 +743,10 @@ IO_READ_PROTO (es1370_readl)
         {
             uint32_t size = ((d->frame_cnt & 0xffff) + 1) << 2;
             uint32_t curr = ((d->frame_cnt >> 16) + 1) << 2;
-            if (curr > size)
+            if (curr > size) {
                 dolog ("read framecnt curr %d, size %d %d\n", curr, size,
                        curr > size);
+            }
         }
 #endif
         break;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 60 lines · Stefan Weil

The patch fixes these gcc warnings:

./hw/es1370.c: In function ?es1370_update_voices?:
./hw/es1370.c:411: error: format ?%d? expects type ?int?, but argument 3 has type ?size_t? ./hw/es1370.c: In function ?es1370_writel?:
./hw/es1370.c:579: error: format ?%d? expects type ?int?, but argument 3 has type ?long int? ./hw/es1370.c:589: error: format ?%d? expects type ?int?, but argument 3 has type ?long int? ./hw/es1370.c:606: error: format ?%d? expects type ?int?, but argument 3 has type ?long int? ./hw/es1370.c: In function ?es1370_readl?:
./hw/es1370.c:748: error: suggest braces around empty body in an ?if? statement

---
 hw/es1370.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
hw/es1370.c +4 -4
index 40cb48c..c87bbf2 100644
@@ -408,7 +408,7 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl)
 
         if ((old_fmt != new_fmt) || (old_freq != new_freq)) {
             d->shift = (new_fmt & 1) + (new_fmt >> 1);
-            ldebug ("channel %d, freq = %d, nchannels %d, fmt %d, shift %d\n",
+            ldebug ("channel %zu, freq = %d, nchannels %d, fmt %d, shift %d\n",
                     i,
                     new_freq,
                     1 << (new_fmt & 1),
@@ -576,7 +576,7 @@ IO_WRITE_PROTO (es1370_writel)
         d++;
     case ES1370_REG_DAC1_SCOUNT:
         d->scount = (val & 0xffff) | (d->scount & ~0xffff);
-        ldebug ("chan %d CURR_SAMP_CT %d, SAMP_CT %d\n",
+        ldebug ("chan %ld CURR_SAMP_CT %d, SAMP_CT %d\n",
                 d - &s->chan[0], val >> 16, (val & 0xffff));
         break;
 
@@ -586,7 +586,7 @@ IO_WRITE_PROTO (es1370_writel)
         d++;
     case ES1370_REG_DAC1_FRAMEADR:
         d->frame_addr = val;
-        ldebug ("chan %d frame address %#x\n", d - &s->chan[0], val);
+        ldebug ("chan %ld frame address %#x\n", d - &s->chan[0], val);
         break;
 
     case ES1370_REG_PHANTOM_FRAMECNT:
@@ -603,7 +603,7 @@ IO_WRITE_PROTO (es1370_writel)
     case ES1370_REG_DAC1_FRAMECNT:
         d->frame_cnt = val;
         d->leftover = 0;
-        ldebug ("chan %d frame count %d, buffer size %d\n",
+        ldebug ("chan %ld frame count %d, buffer size %d\n",
                 d - &s->chan[0], val >> 16, val & 0xffff);
         break;
 
@@ -743,9 +743,10 @@ IO_READ_PROTO (es1370_readl)
         {

hw/es1370.c IO_READ_PROTO (es1370_readl) · line 752

Quoted 10 lines
hw/es1370.c +2 -1
             uint32_t size = ((d->frame_cnt & 0xffff) + 1) << 2;
             uint32_t curr = ((d->frame_cnt >> 16) + 1) << 2;
-            if (curr > size)
+            if (curr > size) {
                 dolog ("read framecnt curr %d, size %d %d\n", curr, size,
                        curr > size);
+            }
         }
 #endif
         break;

typeof(ptr a - ptr b) = ptrdiff, not an %ld here on ppc32, so no, this "fix" is not correct.

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

PATCH v2 1/1 es1370: Fix compiler warnings for debug code

The patch fixes these gcc warnings:

./hw/es1370.c: In function ‘es1370_update_voices’:
./hw/es1370.c:411: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’ ./hw/es1370.c: In function ‘es1370_writel’:
./hw/es1370.c:579: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c:589: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c:606: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c: In function ‘es1370_readl’:
./hw/es1370.c:748: error: suggest braces around empty body in an ‘if’ statement

v2

* Use %zd for pointer differences (ptrdiff_t or ssize_t). The gcc error message ("long int") was misleading. Malc, thank you for this hint.

---
 hw/es1370.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
hw/es1370.c +6 -5
index 40cb48c..591dbd0 100644
@@ -408,7 +408,7 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl)
 
         if ((old_fmt != new_fmt) || (old_freq != new_freq)) {
             d->shift = (new_fmt & 1) + (new_fmt >> 1);
-            ldebug ("channel %d, freq = %d, nchannels %d, fmt %d, shift %d\n",
+            ldebug ("channel %zu, freq = %d, nchannels %d, fmt %d, shift %d\n",
                     i,
                     new_freq,
                     1 << (new_fmt & 1),
@@ -576,7 +576,7 @@ IO_WRITE_PROTO (es1370_writel)
         d++;
     case ES1370_REG_DAC1_SCOUNT:
         d->scount = (val & 0xffff) | (d->scount & ~0xffff);
-        ldebug ("chan %d CURR_SAMP_CT %d, SAMP_CT %d\n",
+        ldebug ("chan %zd CURR_SAMP_CT %d, SAMP_CT %d\n",
                 d - &s->chan[0], val >> 16, (val & 0xffff));
         break;
 
@@ -586,7 +586,7 @@ IO_WRITE_PROTO (es1370_writel)
         d++;
     case ES1370_REG_DAC1_FRAMEADR:
         d->frame_addr = val;
-        ldebug ("chan %d frame address %#x\n", d - &s->chan[0], val);
+        ldebug ("chan %zd frame address %#x\n", d - &s->chan[0], val);
         break;
 
     case ES1370_REG_PHANTOM_FRAMECNT:
@@ -603,7 +603,7 @@ IO_WRITE_PROTO (es1370_writel)
     case ES1370_REG_DAC1_FRAMECNT:
         d->frame_cnt = val;
         d->leftover = 0;
-        ldebug ("chan %d frame count %d, buffer size %d\n",
+        ldebug ("chan %zd frame count %d, buffer size %d\n",
                 d - &s->chan[0], val >> 16, val & 0xffff);
         break;
 
@@ -743,9 +743,10 @@ IO_READ_PROTO (es1370_readl)
         {
             uint32_t size = ((d->frame_cnt & 0xffff) + 1) << 2;
             uint32_t curr = ((d->frame_cnt >> 16) + 1) << 2;
-            if (curr > size)
+            if (curr > size) {
                 dolog ("read framecnt curr %d, size %d %d\n", curr, size,
                        curr > size);
+            }
         }
 #endif
         break;
Signature · 1 line
1.7.1
#3 lore raw
Quoted 11 lines · Stefan Weil

The patch fixes these gcc warnings:

./hw/es1370.c: In function ‘es1370_update_voices’:
./hw/es1370.c:411: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’ ./hw/es1370.c: In function ‘es1370_writel’:
./hw/es1370.c:579: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c:589: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c:606: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c: In function ‘es1370_readl’:
./hw/es1370.c:748: error: suggest braces around empty body in an ‘if’ statement

Quoted 5 lines

v2

* Use %zd for pointer differences (ptrdiff_t or ssize_t). The gcc error message ("long int") was misleading. Malc, thank you for this hint.

The correct length modifier for ptrdiff_t is 't', not 'z'. ISO/IEC 9899:1999 7.19.6.1:

z Specifies that a following d, i, o, u, x, or X
conversion specifier applies to a size_t or the corresponding signed integer type argument; or that a following n conversion specifier applies
to a pointer to a signed integer type
corresponding to size_t argument.

t Specifies that a following d, i, o, u, x, or X
conversion specifier applies to a ptrdiff_t or
the corresponding unsigned integer type
argument; or that a following n conversion specifier applies to a pointer to a ptrdiff_t argument.

Not that it makes a difference in practice.

#4 lore raw

Am 01.10.2010 20:22, schrieb Markus Armbruster:

Quoted 28 lines
Quoted 11 lines · Stefan Weil

The patch fixes these gcc warnings:

./hw/es1370.c: In function ‘es1370_update_voices’:
./hw/es1370.c:411: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’ ./hw/es1370.c: In function ‘es1370_writel’:
./hw/es1370.c:579: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c:589: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c:606: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c: In function ‘es1370_readl’:
./hw/es1370.c:748: error: suggest braces around empty body in an ‘if’ statement

Quoted 5 lines

v2

* Use %zd for pointer differences (ptrdiff_t or ssize_t). The gcc error message ("long int") was misleading. Malc, thank you for this hint.

The correct length modifier for ptrdiff_t is 't', not 'z'. ISO/IEC 9899:1999 7.19.6.1:

z Specifies that a following d, i, o, u, x, or X conversion specifier applies to a size_t or the corresponding signed integer type argument; or that a following n conversion specifier applies to a pointer to a signed integer type corresponding to size_t argument.

Quoted 8 lines

t Specifies that a following d, i, o, u, x, or X conversion specifier applies to a ptrdiff_t or the corresponding unsigned integer type argument; or that a following n conversion specifier applies to a pointer to a ptrdiff_t argument.

Not that it makes a difference in practice.

It's always good to learn more. I must admit that I never used %td before, but it exists, it is obviously supported, so it should be used.

Therefore I'll send a third version of my patch, and also patches which fix the other locations in qemu which use %zd instead of %td for ptrdiff_t.

Thanks,
Stefan

#5 lore raw

PATCH v3 1/1 es1370: Fix compiler warnings for debug code

In reply to Markus Armbruster

The patch fixes these gcc warnings:

./hw/es1370.c: In function ‘es1370_update_voices’:
./hw/es1370.c:411: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’ ./hw/es1370.c: In function ‘es1370_writel’:
./hw/es1370.c:579: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c:589: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c:606: error: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’ ./hw/es1370.c: In function ‘es1370_readl’:
./hw/es1370.c:748: error: suggest braces around empty body in an ‘if’ statement

v2

* Use %zd for pointer differences (ptrdiff_t or ssize_t). The gcc error message ("long int") was misleading. Malc, thank you for this hint.

v3

* Use %td for ptrdiff_t arguments.
Thanks to Markus Armbruster for this hint.

Cc Blue Swirl <[email protected]>
Cc Markus Armbruster <[email protected]>
---
 hw/es1370.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
hw/es1370.c +6 -5
index 40cb48c..850ffc9 100644
@@ -408,7 +408,7 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl)
 
         if ((old_fmt != new_fmt) || (old_freq != new_freq)) {
             d->shift = (new_fmt & 1) + (new_fmt >> 1);
-            ldebug ("channel %d, freq = %d, nchannels %d, fmt %d, shift %d\n",
+            ldebug ("channel %zu, freq = %d, nchannels %d, fmt %d, shift %d\n",
                     i,
                     new_freq,
                     1 << (new_fmt & 1),
@@ -576,7 +576,7 @@ IO_WRITE_PROTO (es1370_writel)
         d++;
     case ES1370_REG_DAC1_SCOUNT:
         d->scount = (val & 0xffff) | (d->scount & ~0xffff);
-        ldebug ("chan %d CURR_SAMP_CT %d, SAMP_CT %d\n",
+        ldebug ("chan %td CURR_SAMP_CT %d, SAMP_CT %d\n",
                 d - &s->chan[0], val >> 16, (val & 0xffff));
         break;
 
@@ -586,7 +586,7 @@ IO_WRITE_PROTO (es1370_writel)
         d++;
     case ES1370_REG_DAC1_FRAMEADR:
         d->frame_addr = val;
-        ldebug ("chan %d frame address %#x\n", d - &s->chan[0], val);
+        ldebug ("chan %td frame address %#x\n", d - &s->chan[0], val);
         break;
 
     case ES1370_REG_PHANTOM_FRAMECNT:
@@ -603,7 +603,7 @@ IO_WRITE_PROTO (es1370_writel)
     case ES1370_REG_DAC1_FRAMECNT:
         d->frame_cnt = val;
         d->leftover = 0;
-        ldebug ("chan %d frame count %d, buffer size %d\n",
+        ldebug ("chan %td frame count %d, buffer size %d\n",
                 d - &s->chan[0], val >> 16, val & 0xffff);
         break;
 
@@ -743,9 +743,10 @@ IO_READ_PROTO (es1370_readl)
         {
             uint32_t size = ((d->frame_cnt & 0xffff) + 1) << 2;
             uint32_t curr = ((d->frame_cnt >> 16) + 1) << 2;
-            if (curr > size)
+            if (curr > size) {
                 dolog ("read framecnt curr %d, size %d %d\n", curr, size,
                        curr > size);
+            }
         }
 #endif
         break;
Signature · 1 line
1.7.1
Applied
#6 lore raw
Quoted 11 lines · Stefan Weil

The patch fixes these gcc warnings:

./hw/es1370.c: In function ?es1370_update_voices?:
./hw/es1370.c:411: error: format ?%d? expects type ?int?, but argument 3 has type ?size_t? ./hw/es1370.c: In function ?es1370_writel?:
./hw/es1370.c:579: error: format ?%d? expects type ?int?, but argument 3 has type ?long int? ./hw/es1370.c:589: error: format ?%d? expects type ?int?, but argument 3 has type ?long int? ./hw/es1370.c:606: error: format ?%d? expects type ?int?, but argument 3 has type ?long int? ./hw/es1370.c: In function ?es1370_readl?:
./hw/es1370.c:748: error: suggest braces around empty body in an ?if? statement

[..snip..]

Thanks, applied.

Signature · 1 line
mailto:[email protected]