Avoid adding the same data member twice in the DWARF reader
authorDodji Seketeli <dodji@redhat.com>
Mon, 18 Sep 2017 14:03:18 +0000 (16:03 +0200)
committerDodji Seketeli <dodji@redhat.com>
Mon, 18 Sep 2017 15:45:30 +0000 (17:45 +0200)
When we face two equivalent highly recursive structs/classes, it can
happen that a given data member be added twice to the type.  When
comparing two versions of a binary in which the data member happens to
have been removed from the second version, we thus trigger an assert
because a given data member has been "removed twice".

This happens on the example provided in PR libabigail/17948 -- which
is too big to be added to the test suite.

This patch hopefully fixes the issue by looking harder at the data
structure to make sure that we don't add the same data member twice.

* src/abg-dwarf-reader.cc (add_or_update_class_type): After a we
try to create a data member type, look *again* if the data member
wasn't added recursively by the creation of the data member type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-dwarf-reader.cc

index f7860061fdab1da01c6a49a950727ff05924eaf3..602ac7e49bfe3d0d39420755811ce858bb0d6b30 100644 (file)
@@ -13041,6 +13041,13 @@ add_or_update_class_type(read_context&  ctxt,
              if (!t)
                continue;
 
+             // The call to build_ir_node_from_die above could have
+             // triggered the adding of a data member named 'n' into
+             // result.  So let's check again if the variable is
+             // already a member of this class.
+             if (lookup_var_decl_in_scope(n, result))
+               continue;
+
              if (!is_static)
                // We have a non-static data member.  So this class
                // cannot be a declaration-only class anymore, even if