Use ODR-based optimization on C/C++ translation unit only
Looking at the debug info of the libgo library (written in Go) it
appears that there can be for instance a public type "int" which is a
4 bytes long in a translation unit, and another type named "int" as
well, and which is 8 bytes long. Having this in C++ is illegal as per
the One Definition Rule (ODR). And generally, in C, we don't have
this either even if C doesn't have an ODR.
Abigail uses the ODR to speed-up type canonicalization. So in cases
where two "int" types (of different sizes) are considered equal
because they have the same name and are in the same binary we end up
with inconsistencies that make comparison tools emit wrong reports.
This patch thus performs the ODR-based optimization only for C and C++
translation units.
Note that while working on this, I noticed that we were not setting
the translation unit of a certain number of ABI artifacts correctly.
This patch fixes that too. We need to set the translation unit of all
ABI artifacts because to get the language of the translation union of
an ABI artifact, we need to get its translation unit first.
* src/abg-ir.cc (strip_typedef): Set the translation unit of the
new ABI artifact.
(type_base::get_canonical_type_for): Perform the ODR-based
optimization only for ABI artifact in C and C++ language
translation units.
* src/abg-dwarf-reader.cc (build_ir_node_from_die): Assert that
the new ABI artifact has its translation unit set.
* src/abg-reader.cc (read_context::{push_decl_to_current_scope,
push_and_key_type_decl}): Set the translation unit of the current
decl, irrespective of if it was added to the current scope or not.
Assert that the decl that was newly pushed to the current scope is
added to the current translation unit.