Make enum values take 64 bits on all platforms

The is still some changes in the way values of enumerators are
represented in 32 and 64 bits systems.  This is because the type of
enumerators is size_t which 32 bits on 32 bits systems and 64 bits on
64 bits systems.  The problem is, the output of, abidw can thus be
different on 32 and 64 bits, making some tests output be different on
these platforms.

This patch thus uses uint64_t to represent enumerator values on all
platforms.

	* include/abg-ir.h: Include stdint.h for int64_t.
	(enumerator::enumerator): Take an int64_t value for the value of
	the enumerator.
	(enumerator::{s,g}et_value): Take/return an int64_t value.
	* src/abg-ir.cc (enum_type_decl::enumerator::priv): Store the
	value in an int64_t.
	(enumerator::priv::priv): Take a int64_t for the value.
	(enum_type_decl::enumerator::enumerator): Likewise.
	(enum_type_decl::enumerator::{s,g}et_value): Take/returnan int64_t
	value.
	* src/abg-dwarf-reader.cc (die_unsigned_constant_attribute): Take
	an uint64_t value.
	(die_signed_constant_attribute): Take an int64_t value.
	(die_location, die_size_in_bits, die_access_specifier)
	(die_virtuality, die_is_virtual, die_is_declared_inline)
	(build_translation_unit_and_add_to_ir, build_type_decl)
	(build_enum_type, build_pointer_type_def, build_array_type):
	Adjust.
	* src/abg-reader.cc (build_enum_type_decl): Adjust.
	* src/abg-writer.cc (write_enum_type_decl): Do not cast the result
	of enumerator::get_value() anymore, it's value is now a int64_t.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
Dodji Seketeli 2016-01-09 01:02:34 +01:00
parent 3422aaf1c6
commit 64375c64d3
5 changed files with 27 additions and 26 deletions

View File

@ -26,6 +26,7 @@
#define __ABG_IR_H__
#include <assert.h>
#include <stdint.h>
#include <cstdlib>
#include <tr1/unordered_map>
#include "abg-fwd.h"
@ -1909,7 +1910,7 @@ public:
enumerator();
enumerator(const string& name, size_t value);
enumerator(const string& name, int64_t value);
enumerator(const enumerator&);
@ -1925,11 +1926,11 @@ public:
void
set_name(const string& n);
size_t
int64_t
get_value() const;
void
set_value(size_t v);
set_value(int64_t v);
enum_type_decl*
get_enum_type() const;

View File

@ -4192,7 +4192,7 @@ die_string_attribute(Dwarf_Die* die, unsigned attr_name)
static bool
die_unsigned_constant_attribute(Dwarf_Die* die,
unsigned attr_name,
size_t& cst)
uint64_t& cst)
{
if (!die)
return false;
@ -4226,7 +4226,7 @@ die_unsigned_constant_attribute(Dwarf_Die* die,
static bool
die_signed_constant_attribute(Dwarf_Die* die,
unsigned attr_name,
ssize_t& cst)
int64_t& cst)
{
if (!die)
return false;
@ -4468,7 +4468,7 @@ die_location(read_context& ctxt, Dwarf_Die* die)
return location();
string file = die_decl_file_attribute(die);
size_t line = 0;
uint64_t line = 0;
die_unsigned_constant_attribute(die, DW_AT_decl_line, line);
if (!file.empty() && line != 0)
@ -4518,7 +4518,7 @@ die_size_in_bits(Dwarf_Die* die, size_t& size)
if (!die)
return false;
size_t byte_size = 0, bit_size = 0;
uint64_t byte_size = 0, bit_size = 0;
if (!die_unsigned_constant_attribute(die, DW_AT_byte_size, byte_size))
{
@ -4548,7 +4548,7 @@ die_access_specifier(Dwarf_Die * die, access_specifier& access)
if (!die)
return false;
size_t a = 0;
uint64_t a = 0;
if (!die_unsigned_constant_attribute(die, DW_AT_accessibility, a))
return false;
@ -4698,7 +4698,7 @@ die_virtuality(Dwarf_Die* die, virtuality& virt)
if (!die)
return false;
size_t v = 0;
uint64_t v = 0;
die_unsigned_constant_attribute(die, DW_AT_virtuality, v);
if (v == DW_VIRTUALITY_virtual)
@ -4736,7 +4736,7 @@ die_is_virtual(Dwarf_Die* die)
static bool
die_is_declared_inline(Dwarf_Die* die)
{
size_t inline_value = 0;
uint64_t inline_value = 0;
if (!die_unsigned_constant_attribute(die, DW_AT_inline, inline_value))
return false;
return inline_value == DW_INL_declared_inlined;
@ -6532,7 +6532,7 @@ build_translation_unit_and_add_to_ir(read_context& ctxt,
ctxt.env(),
address_size));
size_t l = 0;
uint64_t l = 0;
die_unsigned_constant_attribute(die, DW_AT_language, l);
result->set_language(dwarf_language_to_tu_language(l));
@ -6697,7 +6697,7 @@ build_type_decl(read_context& ctxt,
return result;
assert(dwarf_tag(die) == DW_TAG_base_type);
size_t byte_size = 0, bit_size = 0;
uint64_t byte_size = 0, bit_size = 0;
if (!die_unsigned_constant_attribute(die, DW_AT_byte_size, byte_size))
if (!die_unsigned_constant_attribute(die, DW_AT_bit_size, bit_size))
return result;
@ -6754,7 +6754,7 @@ build_enum_type(read_context& ctxt,
enum_is_anonymous = true;
}
size_t size = 0;
uint64_t size = 0;
if (die_unsigned_constant_attribute(die, DW_AT_byte_size, size))
size *= 8;
@ -6782,7 +6782,7 @@ build_enum_type(read_context& ctxt,
string n, m;
location l;
die_loc_and_name(ctxt, &child, loc, n, m);
size_t val = 0;
uint64_t val = 0;
die_unsigned_constant_attribute(&child, DW_AT_const_value, val);
enms.push_back(enum_type_decl::enumerator(n, val));
}
@ -7361,7 +7361,7 @@ build_pointer_type_def(read_context& ctxt,
// if the DIE for the pointer type doesn't have a byte_size
// attribute then we assume the size of the pointer is the address
// size of the current translation unit.
size_t size = ctxt.cur_tu()->get_address_size();
uint64_t size = ctxt.cur_tu()->get_address_size();
if (die_unsigned_constant_attribute(die, DW_AT_byte_size, size))
// The size as expressed by DW_AT_byte_size is in byte, so let's
// convert it to bits.
@ -7449,7 +7449,7 @@ build_reference_type(read_context& ctxt,
// if the DIE for the reference type doesn't have a byte_size
// attribute then we assume the size of the reference is the address
// size of the current translation unit.
size_t size = ctxt.cur_tu()->get_address_size();
uint64_t size = ctxt.cur_tu()->get_address_size();
if (die_unsigned_constant_attribute(die, DW_AT_byte_size, size))
size *= 8;
@ -7678,9 +7678,9 @@ build_array_type(read_context& ctxt,
array_type_def::subranges_type subranges;
translation_unit::language language =
ctxt.current_translation_unit()->get_language();
size_t upper_bound = 0;
size_t lower_bound = get_default_array_lower_bound(language);
size_t count = 0;
uint64_t upper_bound = 0;
uint64_t lower_bound = get_default_array_lower_bound(language);
uint64_t count = 0;
if (dwarf_child(die, &child) == 0)
{

View File

@ -8447,7 +8447,7 @@ operator==(const enum_type_decl_sptr& l, const enum_type_decl_sptr& r)
class enum_type_decl::enumerator::priv
{
string name_;
size_t value_;
int64_t value_;
string qualified_name_;
enum_type_decl* enum_type_;
@ -8459,7 +8459,7 @@ public:
: enum_type_()
{}
priv(const string& name, size_t value, enum_type_decl* e = 0)
priv(const string& name, int64_t value, enum_type_decl* e = 0)
: name_(name),
value_(value),
enum_type_(e)
@ -8476,7 +8476,7 @@ enum_type_decl::enumerator::enumerator()
/// @param name the name of the enumerator.
///
/// @param value the value of the enumerator.
enum_type_decl::enumerator::enumerator(const string& name, size_t value)
enum_type_decl::enumerator::enumerator(const string& name, int64_t value)
: priv_(new priv(name, value))
{}
@ -8543,7 +8543,7 @@ enum_type_decl::enumerator::set_name(const string& n)
///
/// @return the value of the current instance of
/// enum_type_decl::enumerator.
size_t
int64_t
enum_type_decl::enumerator::get_value() const
{return priv_->value_;}
@ -8551,7 +8551,7 @@ enum_type_decl::enumerator::get_value() const
///
/// @param v the new value of the enum_type_decl::enumerator.
void
enum_type_decl::enumerator::set_value(size_t v)
enum_type_decl::enumerator::set_value(int64_t v)
{priv_->value_= v;}
/// Getter for the enum type that this enumerator is for.

View File

@ -3176,7 +3176,7 @@ build_enum_type_decl(read_context& ctxt,
if (xmlStrEqual(n->name, BAD_CAST("enumerator")))
{
string name;
size_t value = 0;
int64_t value = 0;
xml_char_sptr a = xml::build_sptr(xmlGetProp(n, BAD_CAST("name")));
if (a)

View File

@ -1860,7 +1860,7 @@ write_enum_type_decl(const enum_type_decl_sptr decl,
o << "<enumerator name='"
<< i->get_name()
<< "' value='"
<< (ssize_t)i->get_value()
<< i->get_value()
<< "'/>\n";
}