dwarf-reader: get_die_source: always initialize return value

Message ID 20200604103237.53270-1-maennich@google.com
State Superseded
Headers
Series dwarf-reader: get_die_source: always initialize return value |

Commit Message

Matthias Männich June 4, 2020, 10:32 a.m. UTC
  GCC9 with ABIGAIL_DEVEL=1 and ABIGAIL_DEBUG=1 set, regularly emits
-Werror=maybe-uninitialized for the values gathered by get_die_source.
As a counter measure, some of them were initialized before the call to
NO_DEBUG_INFO_DIE_SOURCE, but not all of them, leading to said warning.
In order to overcome this, let get_die_source always initialize the
source to NO_DEBUG_INFO_DIE_SOURCE and adjust the caller to consistently
not do that anymore. This solves the warning and maybe but unlikely (due
to the ABG_ASSERT) avoids some UB.

	* src/abg-dwarf-reader.cc
	(read_context::get_die_source): Always initialize die_source.
	(read_context::ContainerType::get_container): Fix
	initialization of die_source.
	(read_context::compute_canonical_die): Likewise.
	(read_context::get_canonical_die): Likewise.
	(read_context::get_or_compute_canonical_die): Likewise.
	(read_context::associate_die_to_decl): Likewise.
	(read_context::set_canonical_die_offset): Likewise.
	(read_context::schedule_type_for_late_canonicalization): Likewise.
	(read_context::compare_dies): Likewise.
	(read_context::get_parent_die): Likewise.
	(read_context::get_scope_for_die): Likewise.
	(read_context::add_or_update_union_type): Likewise.
	(read_context::maybe_canonicalize_type): Likewise.
	(read_context::build_ir_node_from_die): Likewise.

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 src/abg-dwarf-reader.cc | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)
  

Patch

diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index 05130730d5ec..b3cffbb7a2dd 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -2106,7 +2106,7 @@  public:
     ContainerType&
     get_container(const read_context& ctxt, const Dwarf_Die *die)
     {
-      die_source source = NO_DEBUG_INFO_DIE_SOURCE;
+      die_source source;
       ABG_ASSERT(ctxt.get_die_source(die, source));
       return get_container(source);
     }
@@ -2891,7 +2891,7 @@  public:
 			Dwarf_Die &canonical_die,
 			bool die_as_type) const
   {
-    die_source source = NO_DEBUG_INFO_DIE_SOURCE;
+    die_source source;
 
     ABG_ASSERT(get_die_source(die, source));
 
@@ -3130,7 +3130,7 @@  public:
 			       size_t where,
 			       bool die_as_type) const
   {
-    die_source source = NO_DEBUG_INFO_DIE_SOURCE;
+    die_source source;
     ABG_ASSERT(get_die_source(die, source));
 
     offset_offset_map_type &canonical_dies =
@@ -3248,6 +3248,7 @@  public:
   bool
   get_die_source(const Dwarf_Die *die, die_source &source) const
   {
+    source = NO_DEBUG_INFO_DIE_SOURCE;
     ABG_ASSERT(die);
     return get_die_source(*die, source);
   }
@@ -3353,7 +3354,7 @@  public:
 			size_t where_offset,
 			bool do_associate_by_repr = false)
   {
-    die_source source = NO_DEBUG_INFO_DIE_SOURCE;
+    die_source source;
     ABG_ASSERT(get_die_source(die, source));
 
     die_artefact_map_type& m =
@@ -3981,7 +3982,7 @@  public:
 			   Dwarf_Off canonical_die_offset,
 			   bool die_as_type) const
   {
-    die_source source = NO_DEBUG_INFO_DIE_SOURCE;
+    die_source source;
     ABG_ASSERT(get_die_source(die, source));
 
     Dwarf_Off die_offset = dwarf_dieoffset(const_cast<Dwarf_Die*>(die));
@@ -4562,7 +4563,7 @@  public:
   schedule_type_for_late_canonicalization(const Dwarf_Die *die)
   {
     Dwarf_Off o;
-    die_source source = NO_DEBUG_INFO_DIE_SOURCE;
+    die_source source;
 
     Dwarf_Die equiv_die;
     ABG_ASSERT(get_canonical_die(die, equiv_die,
@@ -11397,8 +11398,7 @@  compare_dies(const read_context& ctxt,
   Dwarf_Off l_offset = dwarf_dieoffset(const_cast<Dwarf_Die*>(l)),
     r_offset = dwarf_dieoffset(const_cast<Dwarf_Die*>(r));
   Dwarf_Off l_canonical_die_offset = 0, r_canonical_die_offset = 0;
-  die_source l_die_source = NO_DEBUG_INFO_DIE_SOURCE,
-    r_die_source = NO_DEBUG_INFO_DIE_SOURCE;
+  die_source l_die_source, r_die_source;
   ABG_ASSERT(ctxt.get_die_source(l, l_die_source));
   ABG_ASSERT(ctxt.get_die_source(r, r_die_source));
 
@@ -11847,8 +11847,7 @@  compare_dies(const read_context& ctxt,
       //
       // In case 'r' has no canonical DIE, then compute it, and then
       // propagate that canonical DIE to 'r'.
-      die_source l_source = NO_DEBUG_INFO_DIE_SOURCE,
-	r_source = NO_DEBUG_INFO_DIE_SOURCE;
+      die_source l_source, r_source;
       ABG_ASSERT(ctxt.get_die_source(l, l_source));
       ABG_ASSERT(ctxt.get_die_source(r, r_source));
       if (!l_has_canonical_die_offset
@@ -12102,7 +12101,7 @@  get_parent_die(const read_context&	ctxt,
 {
   ABG_ASSERT(ctxt.dwarf());
 
-  die_source source = NO_DEBUG_INFO_DIE_SOURCE;
+  die_source source;
   ABG_ASSERT(ctxt.get_die_source(die, source));
 
   const offset_offset_map_type& m = ctxt.die_parent_map(source);
@@ -12238,7 +12237,7 @@  get_scope_for_die(read_context& ctxt,
 		  bool		called_for_public_decl,
 		  size_t	where_offset)
 {
-  die_source source_of_die = NO_DEBUG_INFO_DIE_SOURCE;
+  die_source source_of_die;
   ABG_ASSERT(ctxt.get_die_source(die, source_of_die));
 
   if (is_c_language(ctxt.cur_transl_unit()->get_language()))
@@ -13686,7 +13685,7 @@  add_or_update_union_type(read_context&	ctxt,
   if (tag != DW_TAG_union_type)
     return result;
 
-  die_source source = NO_DEBUG_INFO_DIE_SOURCE;
+  die_source source;
   ABG_ASSERT(ctxt.get_die_source(die, source));
   {
     die_class_or_union_map_type::const_iterator i =
@@ -15777,7 +15776,7 @@  read_debug_info_into_corpus(read_context& ctxt)
 static void
 maybe_canonicalize_type(const Dwarf_Die *die, read_context& ctxt)
 {
-  die_source source = NO_DEBUG_INFO_DIE_SOURCE;
+  die_source source;
   ABG_ASSERT(ctxt.get_die_source(die, source));
 
   size_t die_offset = dwarf_dieoffset(const_cast<Dwarf_Die*>(die));
@@ -15990,7 +15989,7 @@  build_ir_node_from_die(read_context&	ctxt,
 	return result;
     }
 
-  die_source source_of_die = NO_DEBUG_INFO_DIE_SOURCE;
+  die_source source_of_die;
   ABG_ASSERT(ctxt.get_die_source(die, source_of_die));
 
   if ((result = ctxt.lookup_decl_from_die_offset(dwarf_dieoffset(die),