[Bug tdep/26279] New: [s390, Wmaybe-uninitialized] Warnings in opcodes/s390-mkopc.c

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug tdep/26279] New: [s390, Wmaybe-uninitialized] Warnings in opcodes/s390-mkopc.c

Sourceware - gdb-prs mailing list
https://sourceware.org/bugzilla/show_bug.cgi?id=26279

            Bug ID: 26279
           Summary: [s390, Wmaybe-uninitialized] Warnings in
                    opcodes/s390-mkopc.c
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: tdep
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Warnings with -Wall:
...
/home/vries/gdb_versions/devel/src/opcodes/s390-mkopc.c: In function 'main':
/home/vries/gdb_versions/devel/src/opcodes/s390-mkopc.c:171:7: warning:
'ext_table_length' may be used uninitialized in this function
[-Wmaybe-uninitialized]
  171 |   int ext_table_length;
      |       ^~~~~~~~~~~~~~~~
/home/vries/gdb_versions/devel/src/opcodes/s390-mkopc.c:170:38: warning:
'ext_table' may be used uninitialized in this function [-Wmaybe-uninitialized]
  170 |   const struct s390_cond_ext_format *ext_table;
      |                                      ^~~~~~~~~
...

Corresponding code:
...
  const struct s390_cond_ext_format *ext_table;
  int ext_table_length;

  ...

  switch (*tag)
    {
    case '*':
      ext_table = s390_cond_extensions;
      ext_table_length = NUM_COND_EXTENSIONS;
      break;
    case '$':
      ext_table = s390_crb_extensions;
      ext_table_length = NUM_CRB_EXTENSIONS;
      break;
    default: fprintf (stderr, "Unknown tag char: %c\n", *tag);
    }

  for (i = 0; i < ext_table_length; i++)
    {
      char new_mnemonic[15];

      strcpy (new_mnemonic, prefix);
      opcode[mask_start] = ext_table[i].nibble;
      strcat (new_mnemonic, ext_table[i].extension);
      strcat (new_mnemonic, suffix);
      insertOpcode (opcode, new_mnemonic, format, min_cpu, mode_bits, flags);
    }
...

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug tdep/26279] [s390, Wmaybe-uninitialized] Warnings in opcodes/s390-mkopc.c

Sourceware - gdb-prs mailing list
https://sourceware.org/bugzilla/show_bug.cgi?id=26279

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arnez at linux dot ibm.com,
                   |                            |uweigand at sourceware dot org

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug tdep/26279] [s390, Wmaybe-uninitialized] Warnings in opcodes/s390-mkopc.c

Sourceware - gdb-prs mailing list
In reply to this post by Sourceware - gdb-prs mailing list
https://sourceware.org/bugzilla/show_bug.cgi?id=26279

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |s390

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug tdep/26279] [s390, Wmaybe-uninitialized] Warnings in opcodes/s390-mkopc.c

Sourceware - gdb-prs mailing list
In reply to this post by Sourceware - gdb-prs mailing list
https://sourceware.org/bugzilla/show_bug.cgi?id=26279

Andreas Arnez <arnez at linux dot ibm.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |krebbel at linux dot ibm.com

--- Comment #1 from Andreas Arnez <arnez at linux dot ibm.com> ---
This is what seems to happen here:

The function insertExpandedMnemonic() searches for the first occurrence of
'*' or '$' in the given mnemonic and then continues processing based on
the result.  In particular, if one of these "tag characters" is found in
the mnemonic, an extension table is chosen using a switch() on that
character.  The switch statement contains an unreachable default case that
prints an error message and does not set the extension table.  GCC
obviously fails to recognize that this case is unreachable.  Instead it
concludes that the extension table might have been left uninitialized
after the switch statement and consequently emits maybe-uninitialized
warnings for the variables 'ext_table' and 'ext_table_length'.

I assume the false positive can easily be avoided by adding a return statement
after printing the error, or with an appropriate assert() beforehand.  Does
anyone have a preference?

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug tdep/26279] [s390, Wmaybe-uninitialized] Warnings in opcodes/s390-mkopc.c

Sourceware - gdb-prs mailing list
In reply to this post by Sourceware - gdb-prs mailing list
https://sourceware.org/bugzilla/show_bug.cgi?id=26279

--- Comment #2 from Andreas Arnez <arnez at linux dot ibm.com> ---
Created attachment 12726
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12726&action=edit
Handle the default case with abort()

This replaces the fprintf() in the default case by a call to abort().  Not sure
if this helps, since I don't see the warning in my testing.

Tom, which compiler are you using?  Does the patch help?

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug tdep/26279] [s390, Wmaybe-uninitialized] Warnings in opcodes/s390-mkopc.c

Sourceware - gdb-prs mailing list
In reply to this post by Sourceware - gdb-prs mailing list
https://sourceware.org/bugzilla/show_bug.cgi?id=26279

--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Andreas Arnez from comment #2)
> Created attachment 12726 [details]
> Handle the default case with abort()
>
> This replaces the fprintf() in the default case by a call to abort().  Not
> sure if this helps, since I don't see the warning in my testing.
>
> Tom, which compiler are you using?

Warning shows up at -O2, with gcc-7 .. gcc-11.

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug tdep/26279] [s390, Wmaybe-uninitialized] Warnings in opcodes/s390-mkopc.c

Sourceware - gdb-prs mailing list
In reply to this post by Sourceware - gdb-prs mailing list
https://sourceware.org/bugzilla/show_bug.cgi?id=26279

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Andreas Arnez from comment #2)
> Does the patch help?

Yes :)

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug tdep/26279] [s390, Wmaybe-uninitialized] Warnings in opcodes/s390-mkopc.c

Sourceware - gdb-prs mailing list
In reply to this post by Sourceware - gdb-prs mailing list
https://sourceware.org/bugzilla/show_bug.cgi?id=26279

--- Comment #5 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #4)
> (In reply to Andreas Arnez from comment #2)
> > Does the patch help?
>
> Yes :)

Do you want to take care of the commit? If not, I can do it.

--
You are receiving this mail because:
You are on the CC list for the bug.
Reply | Threaded
Open this post in threaded view
|

[Bug tdep/26279] [s390, Wmaybe-uninitialized] Warnings in opcodes/s390-mkopc.c

Sourceware - gdb-prs mailing list
In reply to this post by Sourceware - gdb-prs mailing list
https://sourceware.org/bugzilla/show_bug.cgi?id=26279

Andreas Arnez <arnez at linux dot ibm.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #6 from Andreas Arnez <arnez at linux dot ibm.com> ---
Committed as 9811697376b3f1950419ab13b19e2995703b839b.

--
You are receiving this mail because:
You are on the CC list for the bug.