From 9ab2c3a3fd94116184df5bb0506d09acf59ff54b Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Fri, 28 Aug 2015 17:11:15 +0200 Subject: [PATCH] Use size/alignment of class definition when requested on declaration Sometimes during hashing the "type sub-object" of a class can be queried for its size or alignment. In those case, if the class is a declaration that happens to be accompanied with a definition, its the size/alignment of the definition that we want, not the one of the declaration, that is zero. Otherwise, this can cause spurious hashing changes between two class types that are otherwise equivalent modulo the use of a class declaration. This patch being part of a series that aims at fixing a number of type hashing issues, the regression tests are adjusted at the end of the series, not here. * include/abg-ir.h (type_base::{set_size_in_bits, set_alignment_in_bits}): Make these member functions virtual. (class_decl::{set_size_in_bits, get_size_in_bits, get_alignment_in_bits, set_alignment_in_bits}): Declare these virtual member functions. * src/abg-ir.cc (class_decl::{set_size_in_bits, get_size_in_bits, get_alignment_in_bits, set_alignment_in_bits}): Define these virtual functions. Signed-off-by: Dodji Seketeli --- include/abg-ir.h | 16 +++++++++++-- src/abg-ir.cc | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/include/abg-ir.h b/include/abg-ir.h index 9b9f63a4..bc82abe2 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -1110,13 +1110,13 @@ public: virtual ~type_base(); - void + virtual void set_size_in_bits(size_t); virtual size_t get_size_in_bits() const; - void + virtual void set_alignment_in_bits(size_t); virtual size_t @@ -2650,6 +2650,18 @@ public: class_decl(const std::string& name, bool is_struct, bool is_declaration_only = true); + virtual void + set_size_in_bits(size_t); + + virtual size_t + get_size_in_bits() const; + + virtual size_t + get_alignment_in_bits() const; + + virtual void + set_alignment_in_bits(size_t); + virtual string get_pretty_representation() const; diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 6f24fbf5..527ff938 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -9388,6 +9388,66 @@ class_decl::class_decl(const std::string& name, priv_(new priv(is_declaration_only, is_struct)) {} +/// Setter of the size of the class type. +/// +/// If this class is a declaration of a definition that is elsewhere, +/// then the new size is set to the definition. +/// +/// @param s the new size. +void +class_decl::set_size_in_bits(size_t s) +{ + if (get_is_declaration_only() && get_definition_of_declaration()) + get_definition_of_declaration()->set_size_in_bits(s); + else + type_base::set_size_in_bits(s); +} + +/// Getter of the size of the class type. +/// +/// If this class is a declaration of a definition that is elsewhere, +/// then the size of the definition is returned. +/// +/// @return the size of the class type. +size_t +class_decl::get_size_in_bits() const +{ + if (get_is_declaration_only() && get_definition_of_declaration()) + return get_definition_of_declaration()->get_size_in_bits(); + + return type_base::get_size_in_bits(); +} + +/// Getter of the alignment of the class type. +/// +/// If this class is a declaration of a definition that is elsewhere, +/// then the size of the definition is returned. +/// +/// @return the alignment of the class type. +size_t +class_decl::get_alignment_in_bits() const +{ + if (get_is_declaration_only() && get_definition_of_declaration()) + return get_definition_of_declaration()->get_alignment_in_bits(); + + return type_base::get_alignment_in_bits(); +} + +/// Setter of the alignment of the class type. +/// +/// If this class is a declaration of a definition that is elsewhere, +/// then the new alignment is set to the definition. +/// +/// @param s the new alignment. +void +class_decl::set_alignment_in_bits(size_t a) +{ + if (get_is_declaration_only() && get_definition_of_declaration()) + get_definition_of_declaration()->set_alignment_in_bits(a); + else + type_base::set_alignment_in_bits(a); +} + /// Test if a class is a declaration-only class. /// /// @return true iff the current class is a declaration-only class. -- 2.43.5