forked from Imagelibrary/binutils-gdb
When running test-case gdb.cp/casts.exp with target board unix/-m32, I run into: ... (gdb) print (unsigned long long) &gd == gd_value^M $31 = false^M (gdb) FAIL: gdb.cp/casts.exp: print (unsigned long long) &gd == gd_value ... With some additional printing, we can see in more detail why the comparison fails: ... (gdb) print /x &gd^M $31 = 0xffffc5c8^M (gdb) PASS: gdb.cp/casts.exp: print /x &gd print /x (unsigned long long)&gd^M $32 = 0xffffc5c8^M (gdb) PASS: gdb.cp/casts.exp: print /x (unsigned long long)&gd print /x gd_value^M $33 = 0xffffffffffffc5c8^M (gdb) PASS: gdb.cp/casts.exp: print /x gd_value print (unsigned long long) &gd == gd_value^M $34 = false^M (gdb) FAIL: gdb.cp/casts.exp: print (unsigned long long) &gd == gd_value ... The gd_value is set by this assignment: ... unsigned long long gd_value = (unsigned long long) &gd; ... The problem here is directly casting from a pointer to a non-pointer-sized integer. Fix this by adding an intermediate cast to std::uintptr_t. Tested on x86_64-linux with native and target board unix/-m32.
75 lines
973 B
C++
75 lines
973 B
C++
#include <cstdint>
|
|
|
|
struct A
|
|
{
|
|
int a;
|
|
A (int aa): a (aa) {}
|
|
};
|
|
|
|
struct B: public A
|
|
{
|
|
int b;
|
|
B (int aa, int bb): A (aa), b(bb) {}
|
|
};
|
|
|
|
|
|
struct Alpha
|
|
{
|
|
virtual void x() { }
|
|
};
|
|
|
|
struct Gamma
|
|
{
|
|
};
|
|
|
|
struct Derived : public Alpha
|
|
{
|
|
};
|
|
|
|
struct VirtuallyDerived : public virtual Alpha
|
|
{
|
|
};
|
|
|
|
struct DoublyDerived : public VirtuallyDerived,
|
|
public virtual Alpha,
|
|
public Gamma
|
|
{
|
|
};
|
|
|
|
struct Left
|
|
{
|
|
int left;
|
|
};
|
|
|
|
struct Right
|
|
{
|
|
int right;
|
|
};
|
|
|
|
struct LeftRight : public Left, public Right
|
|
{
|
|
};
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
A *a = new B(42, 1729);
|
|
B *b = (B *) a;
|
|
A &ar = *b;
|
|
B &br = (B&)ar;
|
|
|
|
Derived derived;
|
|
DoublyDerived doublyderived;
|
|
|
|
Alpha *ad = &derived;
|
|
Alpha *add = &doublyderived;
|
|
|
|
LeftRight gd;
|
|
gd.left = 23;
|
|
gd.right = 27;
|
|
unsigned long long gd_value = (unsigned long long) (std::uintptr_t)&gd;
|
|
unsigned long long r_value = (unsigned long long) (Right *) &gd;
|
|
|
|
return 0; /* breakpoint spot: casts.exp: 1 */
|
|
}
|