[applied] ir: Don't overdo canonical type propagation control when comparing classes

Message ID 87ilm1kdjk.fsf@redhat.com
State New
Headers
Series [applied] ir: Don't overdo canonical type propagation control when comparing classes |

Commit Message

Dodji Seketeli Sept. 5, 2022, 4:10 p.m. UTC
  Hello,

While looking at something else, I stumbled upon this problem.

When comparing a class, equals first calls the overload for
class_or_union to compare data members.  If we are in the process of
type canonicalization, the right hand side operand might be
"canonical-type-propagated", during that call to the overload.  In
other words, it can inherit the canonical type of the left-hand-side
operand.  The problem is that that canonical type propagation, if it
happens, is too early because this equals function still needs to
compare other things like virtual member functions etc.  So, the
original intend of the code was to erase the canonical type that might
have been propagated.  This is all and well.

The problem however is that the code /always/ erases the canonical
type of the right hand side operand, even if it was the result of the
propagation optimization long before it entered this equals function.
Oops.

This patch fixes that issue.

	* src/abg-ir.cc (equals): In the overload for const class_decl&,
	do not cancel the propagated canonical type if the propagation is
	not the result of invoking the equals overload for class_or_union.

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

---
 src/abg-ir.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Patch

diff --git a/src/abg-ir.cc b/src/abg-ir.cc
index a2eb8a02..7c8b6640 100644
--- a/src/abg-ir.cc
+++ b/src/abg-ir.cc
@@ -23587,6 +23587,7 @@  equals(const class_decl& l, const class_decl& r, change_kind* k)
   RETURN_TRUE_IF_COMPARISON_CYCLE_DETECTED(static_cast<const class_or_union&>(l),
 					   static_cast<const class_or_union&>(r));
 
+  bool had_canonical_type = !!r.get_naked_canonical_type();
   bool result = true;
   if (!equals(static_cast<const class_or_union&>(l),
 	      static_cast<const class_or_union&>(r),
@@ -23609,7 +23610,8 @@  equals(const class_decl& l, const class_decl& r, change_kind* k)
   // canonical type propagation, then cancel that because it's too
   // early to do that at this point.  We still need to compare bases
   // virtual members.
-  maybe_cancel_propagated_canonical_type(r);
+  if (!had_canonical_type)
+    maybe_cancel_propagated_canonical_type(r);
 
   // Compare bases.
     if (l.get_base_specifiers().size() != r.get_base_specifiers().size())