[1/1] DWARF reader workaround for declaration-only types

Message ID 20200922112921.449335-2-gprocida@google.com
State New
Headers
Series RFC: unexpected declaration-only types |

Commit Message

Giuliano Procida Sept. 22, 2020, 11:29 a.m. UTC
  abidw sometimes unexpectedly emits types as declaration-only (often
just preserving the size information associated with full definitions
elsewhere in the corpus.

This workaround illustrates the issue (it breaks some tests).

Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 src/abg-dwarf-reader.cc | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
  

Patch

diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index 7257052e6..2ff2d0b0f 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -4808,6 +4808,23 @@  public:
 	cn_timer.start();
       }
 
+    {
+      // Partition the types so that definitions appear before declarations.
+      struct Partition {
+	read_context * ctxt;
+	die_source source;
+	bool operator()(Dwarf_Off off) const
+	{
+	  type_base_sptr t = ctxt->lookup_type_from_die_offset(off, source);
+	  decl_base * db = dynamic_cast<decl_base *>(t.get());
+	  return !db || !db->get_is_declaration_only();
+	}
+      };
+      Partition partition { this, source };
+      std::vector<Dwarf_Off>& types = types_to_canonicalize(source);
+      std::partition(types.begin(), types.end(), partition);
+    }
+
     if (!types_to_canonicalize(source).empty())
       {
 	tools_utils::timer single_type_cn_timer;