diff mbox series

[applied] xml-reader: Get back to original way of building qualified types

Message ID 877dfrf8lh.fsf@redhat.com
State New
Headers show
Series [applied] xml-reader: Get back to original way of building qualified types | expand

Commit Message

Dodji Seketeli Sept. 8, 2021, 2:24 p.m. UTC
Hello,

We build qualified types today by building a temporary qualified type
of "void" (one that has no underlying type), then the underlying type
is built, and once it's built, it's set to the qualified type.

We do this so that if during the construction of the underlying type,
the proper qualified type is needed (by recursion) then the temporary
type is found and used.  We used this strategy recently as a temporary
measure until the canonical type propagation algorithm is fixed.  And
now it seems fixed.

The problem with that temporary approach is that in some rare cases,
the temporary qualified void type can be used elsewhere and violate
assertions that expect a proper qualified type.

The patch thus creates the underlying type first.  If the qualified
type is created (by recursion) in the process, we use it.  Otherwise,
the qualified type is later created with the proper underlying type
that is already available.

This helps to fix https://bugzilla.redhat.com/show_bug.cgi?id=1951501.

	* src/abg-reader.cc (build_qualified_type_decl): Create the
	underlying type first, then create the qualified type.
	This helps fix bug

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Applied to master.

---
 src/abg-reader.cc | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/src/abg-reader.cc b/src/abg-reader.cc
index 559f8210..2331815e 100644
--- a/src/abg-reader.cc
+++ b/src/abg-reader.cc
@@ -3672,20 +3672,6 @@  build_qualified_type_decl(read_context&	ctxt,
   if (restrict_cv)
     cv = cv | qualified_type_def::CV_RESTRICT;
 
-  // Create the qualified type /before/ the underlying type.  After
-  // the creation, the type is 'keyed' using
-  // ctxt.push_and_key_type_decl.  This means that the type can be
-  // retrieved from its type ID.  This is so that if the underlying
-  // type indirectly uses this qualified type (via recursion) then
-  // that is made possible.
-  //
-  // The underlying type will later be set after it's created.
-  qualified_type_def_sptr decl;
-  decl.reset(new qualified_type_def(ctxt.get_environment(), cv, loc));
-  maybe_set_artificial_location(ctxt, node, decl);
-  ctxt.push_and_key_type_decl(decl, id, add_to_current_scope);
-  ctxt.map_xml_node_to_decl(node, decl);
-
   string type_id;
   if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "type-id"))
     type_id = CHAR_STR(s);
@@ -3694,7 +3680,21 @@  build_qualified_type_decl(read_context&	ctxt,
   shared_ptr<type_base> underlying_type =
     ctxt.build_or_get_type_decl(type_id, true);
   ABG_ASSERT(underlying_type);
-  decl->set_underlying_type(underlying_type);
+
+  qualified_type_def_sptr decl;
+  if (type_base_sptr t = ctxt.get_type_decl(id))
+    {
+      decl = is_qualified_type(t);
+      ABG_ASSERT(decl);
+    }
+  else
+    {
+      decl.reset(new qualified_type_def(underlying_type, cv, loc));
+      maybe_set_artificial_location(ctxt, node, decl);
+      ctxt.push_and_key_type_decl(decl, id, add_to_current_scope);
+    }
+
+  ctxt.map_xml_node_to_decl(node, decl);
 
   return decl;
 }