diff mbox series

[applied] reader: Build array types with their element type "a priori"

Message ID 871r2os40w.fsf@redhat.com
State New
Headers show
Series [applied] reader: Build array types with their element type "a priori" | expand

Commit Message

Dodji Seketeli Dec. 7, 2021, 5:45 p.m. UTC
Hello,

In some ancient settings, we were building array types with no element
type set, then, when we have the element type built, we'd set it to
the array type.  This was to avoid looping indefinitely in cases where
the element type would indirectly depend on the array type itself.
Since then, we've built infrastructure to avoid those loops.

So we don't need those 'temporarily empty arrays' anymore.  Besides,
trying get the pretty representation of a variable declaration which
type is one of those temporarily empty arrays crashes because that
code doesn't expect empty arrays.

This patch sets the element type at array type building type now.  The
code also asserts that element types of arrays are not empty, in the
pretty representation of variable declarations.

	* src/abg-ir.cc (var_decl::get_pretty_representation): Assert that
	array element types are not empty.
	* src/abg-reader.cc (build_array_type_def): Set array element
	types a priori.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Applied to master.
---
 src/abg-ir.cc     |  7 +++++--
 src/abg-reader.cc | 12 +++++-------
 2 files changed, 10 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/src/abg-ir.cc b/src/abg-ir.cc
index 2cc4cf8c..03b38c3a 100644
--- a/src/abg-ir.cc
+++ b/src/abg-ir.cc
@@ -18497,8 +18497,11 @@  var_decl::get_pretty_representation(bool internal, bool qualified_name) const
       else
 	name = get_qualified_name(internal);
 
-      result +=
-	get_type_declaration(t->get_element_type())->get_qualified_name(internal)
+      type_base_sptr et = t->get_element_type();
+      ABG_ASSERT(et);
+      decl_base_sptr decl = get_type_declaration(et);
+      ABG_ASSERT(decl);
+      result += decl->get_qualified_name(internal)
 	+ " " + name + t->get_subrange_representation();
     }
   else
diff --git a/src/abg-reader.cc b/src/abg-reader.cc
index bf08b2e7..541ca179 100644
--- a/src/abg-reader.cc
+++ b/src/abg-reader.cc
@@ -4282,17 +4282,15 @@  build_array_type_def(read_context&	ctxt,
 	  }
       }
 
-  array_type_def_sptr ar_type(new array_type_def(ctxt.get_environment(),
-						 subranges, loc));
-  maybe_set_artificial_location(ctxt, node, ar_type);
-  if (ctxt.push_and_key_type_decl(ar_type, id, add_to_current_scope))
-    ctxt.map_xml_node_to_decl(node, ar_type);
-
   // The type of array elements.
   type_base_sptr type =
     ctxt.build_or_get_type_decl(type_id, true);
   ABG_ASSERT(type);
-  ar_type->set_element_type(type);
+
+  array_type_def_sptr ar_type(new array_type_def(type, subranges, loc));
+  maybe_set_artificial_location(ctxt, node, ar_type);
+  if (ctxt.push_and_key_type_decl(ar_type, id, add_to_current_scope))
+    ctxt.map_xml_node_to_decl(node, ar_type);
 
   if (dimensions != ar_type->get_dimension_count()
       || (alignment_in_bits