ir: Don't crash when looking at corpus-less translation units
authorDodji Seketeli <dodji@redhat.com>
Fri, 14 Oct 2022 14:06:54 +0000 (16:06 +0200)
committerDodji Seketeli <dodji@redhat.com>
Tue, 25 Oct 2022 14:58:38 +0000 (16:58 +0200)
Back in the early days, there was the possibility to have an ABIXML
output that was just a translation unit.  There was no XML corpus
element holding the abi-instr element.  We still need to support this
going forward.

While looking at something else, I stumbled across spots in the source
code that would crash upon encountering such corpus-less ABIXML
inputs.

Fixed thus.

* src/abg-ir.cc ({decl,type}_topo_comp::operator()): Support types
that inherits from an empty corpus.

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

index b914faaa4ea568b915cb94f5e2e3523730aa3346..5193934a49241432599c1ef8e4974b2743a10a59 100644 (file)
@@ -3353,8 +3353,9 @@ struct decl_topo_comp
 
     // If both decls come from an abixml file, keep the order they
     // have from that abixml file.
-    if (f->get_corpus()->get_origin() == corpus::NATIVE_XML_ORIGIN
-       && s->get_corpus()->get_origin() == corpus::NATIVE_XML_ORIGIN)
+    if ((!f->get_corpus() && !s->get_corpus())
+       || (f->get_corpus()->get_origin() == corpus::NATIVE_XML_ORIGIN
+           && s->get_corpus()->get_origin() == corpus::NATIVE_XML_ORIGIN))
       return compare_using_locations(f, s);
 
     // If a decl has artificial location, then use that one over the
@@ -3451,8 +3452,9 @@ struct type_topo_comp
   {
     // If both decls come from an abixml file, keep the order they
     // have from that abixml file.
-    if (f->get_corpus()->get_origin() == corpus::NATIVE_XML_ORIGIN
-       && s->get_corpus()->get_origin() == corpus::NATIVE_XML_ORIGIN)
+    if ((!f->get_corpus() && !s->get_corpus())
+       || (f->get_corpus()->get_origin() == corpus::NATIVE_XML_ORIGIN
+           && s->get_corpus()->get_origin() == corpus::NATIVE_XML_ORIGIN))
       return compare_using_locations(is_decl(f), is_decl(s));
 
     bool f_is_ptr_ref_or_qual = is_ptr_ref_or_qual_type(f);