[Bug c++/64755] Error in optimization with std::array

2015-01-26 Thread nubcrack at yahoo dot es
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64755

--- Comment #5 from Alejandro Rivero PĂ©rez nubcrack at yahoo dot es ---
Yes, my bad, with no-strict-aliasing the code compiles OK and generate the
desire output. After read more info about strict-aliasing that definitely is
the problem, thanks for the help, sorry for the trouble.

[Bug c++/64755] Error in optimization with std::array

2015-01-26 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64755

Richard Biener rguenth at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #4 from Richard Biener rguenth at gcc dot gnu.org ---
Indeed.


[Bug c++/64755] Error in optimization with std::array

2015-01-25 Thread mednafen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64755

mednafen at gmail dot com changed:

   What|Removed |Added

 CC||mednafen at gmail dot com

--- Comment #2 from mednafen at gmail dot com ---
It looks like your code violates strict aliasing rules.  Does the code in
question work as you intend it to if you compile with -fno-strict-aliasing ?


[Bug c++/64755] Error in optimization with std::array

2015-01-25 Thread mednafen at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64755

--- Comment #3 from mednafen at gmail dot com ---
It looks like your code violates strict aliasing rules.  Does the code in
question work as you intend it to if you compile with -fno-strict-aliasing ?


[Bug c++/64755] Error in optimization with std::array

2015-01-24 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64755

--- Comment #1 from Jonathan Wakely redi at gcc dot gnu.org ---
Comment on attachment 34556
  -- https://gcc.gnu.org/bugzilla/attachment.cgi?id=34556
They are 3 files bug.cpp (contain the code to compile), bug.O1 and bug.O2
(contain the assembly code generated by g++) witch return 0 in O1 or -1 in O2..

Code from the attachment to save having to unrar it:

#include array

template typename All, typename Left, typename Rigth
struct basic_reg {
union {
All value;
struct {
Rigth lower;
Left higher;
} halfs;
};
};

template typename Left
struct basic_regLeft, Left, void {
Left value;
};

template typename Register, unsigned short Size
struct basic_registers {
typedef Register register_t;
typedef std::arrayregister_t, Size registers_t;
basic_registers() : m_registers{0} {}
typename registers_t::reference
operator[](typename registers_t::size_type i) {
return m_registers[i];
}

private:
registers_t m_registers;
};

typedef basic_reguint8_t, uint8_t, void bits_08_register;
typedef basic_reguint16_t, bits_08_register, bits_08_register
bits_16_register;
typedef basic_reguint32_t, bits_16_register, bits_16_register
bits_32_register;
typedef basic_registersbits_32_register, 1 igpr_bits_32_registers;

struct basic_registry_wrapper {
typedef std::arrayuint16_t*, 1 gp_bit16_array;
typedef std::arrayuint32_t*, 1 gp_bit32_array;

basic_registry_wrapper(igpr_bits_32_registers registers) {
m_gpr_bits16_array[0] = registers[0].halfs.lower.value;
m_gpr_bits32_array[0] = registers[0].value;
}

uint16_t ax() { return *m_gpr_bits16_array[0]; }
uint32_t eax() { return *m_gpr_bits32_array[0]; }

private:
gp_bit16_array m_gpr_bits16_array;
gp_bit32_array m_gpr_bits32_array;
};

int main() {
igpr_bits_32_registers reg_32;
basic_registry_wrapper reg_wrap_32(reg_32);

if (reg_wrap_32.eax() != 0)
return -1;
reg_wrap_32.eax() = 0x12345678;
if (reg_wrap_32.ax() != 0x5678)
return -1;
return 0;
}