public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64755] New: Error in optimization with std::array
@ 2015-01-23 21:30 nubcrack at yahoo dot es
  2015-01-24 15:12 ` [Bug c++/64755] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: nubcrack at yahoo dot es @ 2015-01-23 21:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64755

            Bug ID: 64755
           Summary: Error in optimization with std::array
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nubcrack at yahoo dot es

Created attachment 34556
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34556&action=edit
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..

The code provide access to emulated registers of x86:

-class basic_reg represent an x86 register. Could be registers that have access
to higher and lower part (ex: eax -> _,ax -> ah,al). Or registers that don't
need this access (ex: al, ah).
-class basic_registers represent a container of basic_reg (ex: 8 general
purpose registers in x86).
-class basic_registry_wrapper contain the address of the registers of size
16bits or 32bits of the container in class basic_registers and provide easy
access to specific register (ex: eax).

The code in main is a piece of unit test, trying to test that when registers
are modified by basic_registry_wrapper and accessed by basic_registers the
value accessed is the same (even if different parts of the registers are
request or set. Setting AX need to modify the lower part of EAX.

In the attach files .O1 (generated with g++ -S -O1 -o .O1 .cpp) return 0 (no
error) as expected and the .O2 (generated with g++ -S -O2 -o .O2 .cpp) return
-1 (error).

In the two assembly output the code is optimized away completely. When the
default constructor of basic_registers (line "basic_registers() :
m_registers{0} {}") is removed the code work in O1, O2 and O3.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/64755] Error in optimization with std::array
  2015-01-23 21:30 [Bug c++/64755] New: Error in optimization with std::array nubcrack at yahoo dot es
@ 2015-01-24 15:12 ` redi at gcc dot gnu.org
  2015-01-25 21:36 ` mednafen at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2015-01-24 15:12 UTC (permalink / raw)
  To: gcc-bugs

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_reg<Left, Left, void> {
    Left value;
};

template <typename Register, unsigned short Size>
struct basic_registers {
    typedef Register register_t;
    typedef std::array<register_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_reg<uint8_t, uint8_t, void> bits_08_register;
typedef basic_reg<uint16_t, bits_08_register, bits_08_register>
    bits_16_register;
typedef basic_reg<uint32_t, bits_16_register, bits_16_register>
    bits_32_register;
typedef basic_registers<bits_32_register, 1> igpr_bits_32_registers;

struct basic_registry_wrapper {
    typedef std::array<uint16_t*, 1> gp_bit16_array;
    typedef std::array<uint32_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;
}


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/64755] Error in optimization with std::array
  2015-01-23 21:30 [Bug c++/64755] New: Error in optimization with std::array nubcrack at yahoo dot es
  2015-01-24 15:12 ` [Bug c++/64755] " redi at gcc dot gnu.org
  2015-01-25 21:36 ` mednafen at gmail dot com
@ 2015-01-25 21:36 ` mednafen at gmail dot com
  2015-01-26 13:20 ` nubcrack at yahoo dot es
  3 siblings, 0 replies; 5+ messages in thread
From: mednafen at gmail dot com @ 2015-01-25 21:36 UTC (permalink / raw)
  To: gcc-bugs

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 ?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/64755] Error in optimization with std::array
  2015-01-23 21:30 [Bug c++/64755] New: Error in optimization with std::array nubcrack at yahoo dot es
  2015-01-24 15:12 ` [Bug c++/64755] " redi at gcc dot gnu.org
@ 2015-01-25 21:36 ` mednafen at gmail dot com
  2015-01-25 21:36 ` mednafen at gmail dot com
  2015-01-26 13:20 ` nubcrack at yahoo dot es
  3 siblings, 0 replies; 5+ messages in thread
From: mednafen at gmail dot com @ 2015-01-25 21:36 UTC (permalink / raw)
  To: gcc-bugs

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 ?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/64755] Error in optimization with std::array
  2015-01-23 21:30 [Bug c++/64755] New: Error in optimization with std::array nubcrack at yahoo dot es
                   ` (2 preceding siblings ...)
  2015-01-25 21:36 ` mednafen at gmail dot com
@ 2015-01-26 13:20 ` nubcrack at yahoo dot es
  3 siblings, 0 replies; 5+ messages in thread
From: nubcrack at yahoo dot es @ 2015-01-26 13:20 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 2855 bytes --]

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.
>From gcc-bugs-return-474873-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Jan 26 13:31:53 2015
Return-Path: <gcc-bugs-return-474873-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 13443 invoked by alias); 26 Jan 2015 13:31:49 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 13368 invoked by uid 48); 26 Jan 2015 13:31:40 -0000
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/64766] [4.8/4.9/5 Regression] internal compiler error: tree check: expected block, have error_mark in lower_function_body, at gimple-low.c:122
Date: Mon, 26 Jan 2015 13:31:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: middle-end
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords: error-recovery, ice-on-invalid-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jakub at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P4
X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.8.5
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status assigned_to attachments.created
Message-ID: <bug-64766-4-iMtohlK5QO@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-64766-4@http.gcc.gnu.org/bugzilla/>
References: <bug-64766-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-01/txt/msg02867.txt.bz2
Content-length: 571

https://gcc.gnu.org/bugzilla/show_bug.cgi?idd766

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 34572
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id4572&actioníit
gcc5-pr64766.patch

Untested fix.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-01-26 13:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-23 21:30 [Bug c++/64755] New: Error in optimization with std::array nubcrack at yahoo dot es
2015-01-24 15:12 ` [Bug c++/64755] " redi at gcc dot gnu.org
2015-01-25 21:36 ` mednafen at gmail dot com
2015-01-25 21:36 ` mednafen at gmail dot com
2015-01-26 13:20 ` nubcrack at yahoo dot es

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).