Skip to contentSkip to conversation

intc/i8259: avoid (false positive) gcc warning

PATCH In review Christian Borntraeger 4 participants 5 messages Mar 18, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 intc/i8259: avoid (false positive) gcc warning

some copiler versions are smart enough to detect a potentially uninitialized variable, but are not smart enough to detect that this cannot happen due to the code flow:

../hw/intc/i8259.c: In function ‘pic_read_irq’:
../hw/intc/i8259.c:203:13: error: ‘irq2’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

   203 |         irq = irq2 + 8;
       |         ~~~~^~~~~~~~~~

Let us initialize irq2 to -1 to avoid this warning as the most simple solution.

---
 hw/intc/i8259.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/i8259.c +1 -1
index 344fd04db14d..ade6fb726faf 100644
@@ -176,7 +176,7 @@ static void pic_intack(PICCommonState *s, int irq)
 int pic_read_irq(DeviceState *d)
 {
     PICCommonState *s = PIC_COMMON(d);
-    int irq, irq2, intno;
+    int irq, irq2 = -1, intno;
 
     irq = pic_get_irq(s);
     if (irq >= 0) {
Signature · 1 line
2.30.2
#1 lore raw
Quoted 11 lines · Christian Borntraeger

some copiler versions are smart enough to detect a potentially uninitialized variable, but are not smart enough to detect that this cannot happen due to the code flow:

../hw/intc/i8259.c: In function ‘pic_read_irq’:
../hw/intc/i8259.c:203:13: error: ‘irq2’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

    203 |         irq = irq2 + 8;
        |         ~~~~^~~~~~~~~~

Let us initialize irq2 to -1 to avoid this warning as the most simple solution.

What about:

hw/intc/i8259.c +3 -5
index 344fd04db1..bf28c179de 100644
@@ -189,20 +189,18 @@ int pic_read_irq(DeviceState *d)
                 irq2 = 7;
             }
             intno = slave_pic->irq_base + irq2;
+            irq = irq2 + 8;
+            pic_intack(s, 2);
         } else {
             intno = s->irq_base + irq;
+            pic_intack(s, irq);
         }
-        pic_intack(s, irq);
     } else {
         /* spurious IRQ on host controller */
         irq = 7;
         intno = s->irq_base + irq;
     }
 
-    if (irq == 2) {
-        irq = irq2 + 8;
-    }
-
 #ifdef DEBUG_IRQ_LATENCY
     printf("IRQ%d latency=%0.3fus\n",
            irq,

?

Paolo

#2 lore raw
Quoted 10 lines · Paolo Bonzini
Quoted 9 lines · Christian Borntraeger

some copiler versions are smart enough to detect a potentially uninitialized variable, but are not smart enough to detect that this cannot happen due to the code flow:

../hw/intc/i8259.c: In function ‘pic_read_irq’:
../hw/intc/i8259.c:203:13: error: ‘irq2’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 203 |         irq = irq2 + 8;
        |         ~~~~^~~~~~~~~~

Quoted 4 lines
Quoted 2 lines

Let us initialize irq2 to -1 to avoid this warning as the most simple solution.

What about:

This also works, but if you want to go down that path then it would be good if you could do this patch as I do not have the testing infrastructure to do proper x86 changes.

Quoted 35 lines
hw/intc/i8259.c +3 -5
index 344fd04db1..bf28c179de 100644
@@ -189,20 +189,18 @@ int pic_read_irq(DeviceState *d)
                  irq2 = 7;
              }
              intno = slave_pic->irq_base + irq2;
+            irq = irq2 + 8;
+            pic_intack(s, 2);
          } else {
              intno = s->irq_base + irq;
+            pic_intack(s, irq);
          }
-        pic_intack(s, irq);
      } else {
          /* spurious IRQ on host controller */
          irq = 7;
          intno = s->irq_base + irq;
      }
 
-    if (irq == 2) {
-        irq = irq2 + 8;
-    }
-
  #ifdef DEBUG_IRQ_LATENCY
      printf("IRQ%d latency=%0.3fus\n",
             irq,

?

Paolo

#3 lore raw
Quoted 44 lines · Christian Borntraeger
Quoted 11 lines · Paolo Bonzini
Quoted 10 lines · Christian Borntraeger

some copiler versions are smart enough to detect a potentially uninitialized variable, but are not smart enough to detect that this cannot happen due to the code flow:

../hw/intc/i8259.c: In function ‘pic_read_irq’:
../hw/intc/i8259.c:203:13: error: ‘irq2’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    203 |         irq = irq2 + 8;
        |         ~~~~^~~~~~~~~~

Quoted 4 lines
Quoted 2 lines

Let us initialize irq2 to -1 to avoid this warning as the most simple solution.

What about:

This also works, but if you want to go down that path then it would be good if you
could do this patch as I do not have the testing infrastructure to do proper x86
changes.

Quoted 22 lines
hw/intc/i8259.c +3 -1
index 344fd04db1..bf28c179de 100644
@@ -189,20 +189,18 @@ int pic_read_irq(DeviceState *d)
                   irq2 = 7;
               }
               intno = slave_pic->irq_base + irq2;
+            irq = irq2 + 8;
+            pic_intack(s, 2);
           } else {
               intno = s->irq_base + irq;
+            pic_intack(s, irq);
           }
-        pic_intack(s, irq);
       } else {
           /* spurious IRQ on host controller */
           irq = 7;
           intno = s->irq_base + irq;
       }
 
Quoted 4 lines

hw/intc/i8259.c int pic_read_irq(DeviceState *d) · line 205

Quoted 4 lines
hw/intc/i8259.c +0 -4
-    if (irq == 2) {
-        irq = irq2 + 8;
-    }
-

This looks like the patch I just sent :)

#4 lore raw
Quoted 45 lines · Philippe Mathieu-Daudé
Quoted 44 lines · Christian Borntraeger
Quoted 11 lines · Paolo Bonzini
Quoted 10 lines · Christian Borntraeger

some copiler versions are smart enough to detect a potentially uninitialized variable, but are not smart enough to detect that this cannot happen due to the code flow:

../hw/intc/i8259.c: In function ‘pic_read_irq’:
../hw/intc/i8259.c:203:13: error: ‘irq2’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    203 |         irq = irq2 + 8;
        |         ~~~~^~~~~~~~~~

Quoted 4 lines
Quoted 2 lines

Let us initialize irq2 to -1 to avoid this warning as the most simple solution.

What about:

This also works, but if you want to go down that path then it would be good if you
could do this patch as I do not have the testing infrastructure to do proper x86
changes.

Quoted 22 lines
hw/intc/i8259.c +3 -1
index 344fd04db1..bf28c179de 100644
@@ -189,20 +189,18 @@ int pic_read_irq(DeviceState *d)
                   irq2 = 7;
               }
               intno = slave_pic->irq_base + irq2;
+            irq = irq2 + 8;
+            pic_intack(s, 2);
           } else {
               intno = s->irq_base + irq;
+            pic_intack(s, irq);
           }
-        pic_intack(s, irq);
       } else {
           /* spurious IRQ on host controller */
           irq = 7;
           intno = s->irq_base + irq;
       }
 
Quoted 6 lines
Quoted 4 lines

hw/intc/i8259.c int pic_read_irq(DeviceState *d) · line 205

Quoted 4 lines
hw/intc/i8259.c +0 -4
-    if (irq == 2) {
-        irq = irq2 + 8;
-    }
-

This looks like the patch I just sent :)

Except this is simpler and more straightforward. I like this better FWIW.

Regards,
BALATON Zoltan