This is the mail archive of the gdb-testers@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Silence -Wmaybe-uninitialized warning in minsyms.c:lookup_minimal_symbol_by_pc_section


*** TEST RESULTS FOR COMMIT 6ae502670996ec6e8b574dbaa4577d79fa9e9799 ***

Author: Pedro Alves <palves@redhat.com>
Branch: master
Commit: 6ae502670996ec6e8b574dbaa4577d79fa9e9799

Silence -Wmaybe-uninitialized warning in minsyms.c:lookup_minimal_symbol_by_pc_section

Compiling with GCC 8.1 shows this warning:

  gdb/minsyms.c: In function 'bound_minimal_symbol lookup_minimal_symbol_by_pc_section(CORE_ADDR, obj_section*, lookup_msym_prefer)':
  gdb/minsyms.c:825:40: warning: 'want_type' may be used uninitialized in this function [-Wmaybe-uninitialized]
	   && MSYMBOL_TYPE (&msymbol[hi]) != want_type

That warning is a false positive, because the switch that converts
enum lookup_msym_prefer values to enum enum minimal_symbol_type values
has a case for every lookup_msym_prefer enumerator:

  switch (prefer)
   {
    case lookup_msym_prefer::TEXT:
      want_type = mst_text;
      break;
    case lookup_msym_prefer::TRAMPOLINE:
      want_type = mst_solib_trampoline;
      break;
    case lookup_msym_prefer::GNU_IFUNC:
      want_type = mst_text_gnu_ifunc;
      break;
    }

The problem is that GCC assumes that enum variables may hold values
other than the named enumerators (like e.g., "lookup_msym_prefer
prefer = (lookup_msym_prefer) 10;").

Rework the code a bit, adding a gdb_assert to make it explicit to the
compiler that want_type is initialized in all normal-return paths.

gdb/ChangeLog:
2018-06-19  Pedro Alves  <palves@redhat.com>

	* minsyms.c (msym_prefer_to_msym_type): New, factored out from ...
	(lookup_minimal_symbol_by_pc_section): ... here with
	gdb_assert_not_reached added.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]