[applied] ir: Don't crash when looking at corpus-less translation units

Message ID 874jvrot0x.fsf@redhat.com
State New
Headers
Series [applied] ir: Don't crash when looking at corpus-less translation units |

Commit Message

Dodji Seketeli Oct. 26, 2022, 9:04 a.m. UTC
  Hello,

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>
Applied to master.
---
 src/abg-ir.cc | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
  

Patch

diff --git a/src/abg-ir.cc b/src/abg-ir.cc
index b914faaa..5193934a 100644
--- a/src/abg-ir.cc
+++ b/src/abg-ir.cc
@@ -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);