https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116221
anlauf at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |anlauf at gcc dot gnu.org --- Comment #3 from anlauf at gcc dot gnu.org --- (In reply to Sam James from comment #0) > 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); > } I can imagine that it is difficult to prove that in gfc_get_ha_symbol st always gets set before the test. Does it help to initialize it? diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc index b5143d9f790..a8b623dd92a 100644 --- a/gcc/fortran/symbol.cc +++ b/gcc/fortran/symbol.cc @@ -3599,7 +3599,7 @@ int gfc_get_ha_symbol (const char *name, gfc_symbol **result) { int i; - gfc_symtree *st; + gfc_symtree *st = NULL; i = gfc_get_ha_sym_tree (name, &st);