public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: Dodji Seketeli <dodji@redhat.com>
To: libabigail@sourceware.org
Subject: [PATCH, applied] xml-reader: Get back to original way of building qualified types
Date: Wed, 08 Sep 2021 16:24:58 +0200	[thread overview]
Message-ID: <877dfrf8lh.fsf@redhat.com> (raw)

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 --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;
 }
-- 
2.30.0


-- 
		Dodji


                 reply	other threads:[~2021-09-08 14:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877dfrf8lh.fsf@redhat.com \
    --to=dodji@redhat.com \
    --cc=libabigail@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).