https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116221

            Bug ID: 116221
           Summary: -Wmaybe-uninitialized in gfc_get_ha_symbol
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: build
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sjames at gcc dot gnu.org
            Blocks: 24639, 44756
  Target Milestone: ---

With an LTO bootstrap, I saw the following:
```
/var/tmp/portage/sys-devel/gcc-15.0.9999/work/gcc-15.0.9999/gcc/fortran/symbol.cc:
In function ‘gfc_get_ha_symbol’:
/var/tmp/portage/sys-devel/gcc-15.0.9999/work/gcc-15.0.9999/gcc/fortran/symbol.cc:3606:7:
warning: ‘st’ may be used uninitialized [-Wmaybe-uninitialized]
 3606 |   if (st)
      |       ^
/var/tmp/portage/sys-devel/gcc-15.0.9999/work/gcc-15.0.9999/gcc/fortran/symbol.cc:3602:16:
note: ‘st’ declared here
 3602 |   gfc_symtree *st;
      |                ^
```

At a glance, it looks like it might be right.

```
int
gfc_get_ha_symbol (const char *name, gfc_symbol **result)
{
  int i;
  gfc_symtree *st;

  i = gfc_get_ha_sym_tree (name, &st);

  if (st)
    *result = st->n.sym;
  else
    *result = NULL;

  return i;
}
```

We always test st after calling gfc_get_ha_sym_tree, but gfc_get_ha_sym_tree
doesn't _always_ initialise st (result):

int
gfc_get_ha_sym_tree (const char *name, gfc_symtree **result)
{
  gfc_symtree *st;
  int i;

  i = gfc_find_sym_tree (name, gfc_current_ns, 0, &st);

  if (st != NULL)
    {
      gfc_save_symbol_data (st->n.sym);
      *result = st;
      return i;
    }

  i = gfc_find_sym_tree (name, gfc_current_ns, 1, &st);
  if (i)
    return i;

  if (st != NULL)
    {
      *result = st;
      return 0;
    }

  return gfc_get_sym_tree (name, gfc_current_ns, result, false);
}


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639
[Bug 24639] [meta-bug] bug to track all Wuninitialized issues
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44756
[Bug 44756] [meta-bug] --enable-werror-always issues

Reply via email to