public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57693] New: The program logically failed in case of used "int b += b++"
@ 2013-06-24  7:46 vlad94009277 at gmail dot com
  2013-06-24  7:49 ` [Bug c++/57693] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vlad94009277 at gmail dot com @ 2013-06-24  7:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57693

            Bug ID: 57693
           Summary: The program logically failed in case of used "int b +=
                    b++"
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vlad94009277 at gmail dot com

Steps to reproduce:

1. Write the following source cod and compile it:

#include <iostream>
using namespace std;

int main(){
        int d = 7;
        int c = 7;
        int &b = c;
        b += b++;
        d += d++;
        cout << "c = "<< c << endl;
        cout << "d = "<< d << endl;
return 0;
}

2. Run the appropriate generated executable file.

Actual result: 
It's printed:
c = 8
d = 15

Expected result:
It should be printed:
c = 15
d = 15

Please note that there are different assemble codes for used operators:

1) d += d++
movl -4(%rbp), %eax // Copies value of d to register %eax
addl %eax, %eax // Adds %eax to %eax, remembers the value in %eax
movl %eax, -4(%rbp) // Moves %eax to d (d = 14)
addl $1, -4(%rbp) // Increments the value of d (d = 15)

2) b += b++

movl -12(%rbp), %eax // Moves the value of b to %eax
movl -12(%rbp), %edx // Moves the value of b to %edx
leal (%rax,%rdx), %edx // Adds %rax to %rdx and stores result in %edx (%rax and
%rdx are equal to 7, so after this operation %edx is 14)
movl %edx, -12(%rbp) // Moves %edx to d (d = 14)
addl $1, %eax // Increments the value of %eax (%eax = 8).
movl %eax, -12(%rbp) // Moves %eax to d (d = 8)


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

* [Bug c++/57693] The program logically failed in case of used "int b += b++"
  2013-06-24  7:46 [Bug c++/57693] New: The program logically failed in case of used "int b += b++" vlad94009277 at gmail dot com
@ 2013-06-24  7:49 ` pinskia at gcc dot gnu.org
  2013-06-24  8:15 ` vlad94009277 at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-06-24  7:49 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57693

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Both:
 b += b++;
And
        d += d++;

are undefined what value b and d is going to be as there are no sequence point
intbetween the two assignments.

They could be:
temp = b;
b++;
b += temp;

or b++;
b+=b;


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

* [Bug c++/57693] The program logically failed in case of used "int b += b++"
  2013-06-24  7:46 [Bug c++/57693] New: The program logically failed in case of used "int b += b++" vlad94009277 at gmail dot com
  2013-06-24  7:49 ` [Bug c++/57693] " pinskia at gcc dot gnu.org
@ 2013-06-24  8:15 ` vlad94009277 at gmail dot com
  2013-06-24  8:18 ` jakub at gcc dot gnu.org
  2013-06-24 10:05 ` manu at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: vlad94009277 at gmail dot com @ 2013-06-24  8:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57693

--- Comment #2 from Vladimir <vlad94009277 at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> Both:
>  b += b++;
> And
>         d += d++;
> 
> are undefined what value b and d is going to be as there are no sequence
> point intbetween the two assignments.
> 
> They could be:
> temp = b;
> b++;
> b += temp;
> 
> or b++;
> b+=b;

I tried this issue on version 4.8.1 and it works successfully.
It seems the bug was already fixed.


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

* [Bug c++/57693] The program logically failed in case of used "int b += b++"
  2013-06-24  7:46 [Bug c++/57693] New: The program logically failed in case of used "int b += b++" vlad94009277 at gmail dot com
  2013-06-24  7:49 ` [Bug c++/57693] " pinskia at gcc dot gnu.org
  2013-06-24  8:15 ` vlad94009277 at gmail dot com
@ 2013-06-24  8:18 ` jakub at gcc dot gnu.org
  2013-06-24 10:05 ` manu at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-06-24  8:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57693

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
You are not listening, the only bug here is in your testcase, not in the
compiler.


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

* [Bug c++/57693] The program logically failed in case of used "int b += b++"
  2013-06-24  7:46 [Bug c++/57693] New: The program logically failed in case of used "int b += b++" vlad94009277 at gmail dot com
                   ` (2 preceding siblings ...)
  2013-06-24  8:18 ` jakub at gcc dot gnu.org
@ 2013-06-24 10:05 ` manu at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2013-06-24 10:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57693

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
> Both:
>  b += b++;
> And
>         d += d++;
> 
> are undefined what value b and d is going to be as there are no sequence
> point intbetween the two assignments.
> 
> They could be:
> temp = b;
> b++;
> b += temp;
> 
> or b++;
> b+=b;

Please, could we make more use of the FAQ? 

http://gcc.gnu.org/wiki/FAQ#undefinedbut

If you think the answer does not provide enough information, just extend the
answer there. (it could mention some example, and -Wsequence-points).

Otherwise, we have the same back and forth over and over again to the
frustration of users and the time waste of developers: what is UB? but my
program worked before! but my program works without optimizations! but I know
how it should work! can't gcc be consistent? but UB should not affect my
problem! I think this should not be UB!
>From gcc-bugs-return-424969-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Jun 24 10:15:22 2013
Return-Path: <gcc-bugs-return-424969-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 5950 invoked by alias); 24 Jun 2013 10:15:22 -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 5896 invoked by uid 48); 24 Jun 2013 10:15:18 -0000
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/57696] New: Defined assignment for components not used when those are ALLOCATABLE
Date: Mon, 24 Jun 2013 10:15:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: fortran
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords: wrong-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: burnus at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter cc
Message-ID: <bug-57696-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: 2013-06/txt/msg01348.txt.bz2
Content-length: 1290

http://gcc.gnu.org/bugzilla/show_bug.cgi?idW696

            Bug ID: 57696
           Summary: Defined assignment for components not used when those
                    are ALLOCATABLE
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: pault at gcc dot gnu.org

The following prints
          42
          42
with gfortran and
 42
 20
with crayftn. Thus, gfortran does not use defined assignment - but it should.

Note: If "right%foo" is not allocated, the code segfaults with crayftn.


module m0
  implicit none
  type component
    integer :: i = 42
  contains
    procedure :: assign0
    generic :: assignment(=) => assign0
  end type
  type parent
    type(component), allocatable :: foo
  end type
contains
  elemental subroutine assign0(lhs,rhs)
    class(component), intent(INout) :: lhs
    class(component), intent(in) :: rhs
    lhs%i = 20
  end subroutine
end module

program main
  use m0
  implicit none
  type(parent) :: left, right
  allocate(right%foo)
  print *, right%foo
  left = right
  print *, left%foo
end


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

end of thread, other threads:[~2013-06-24 10:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-24  7:46 [Bug c++/57693] New: The program logically failed in case of used "int b += b++" vlad94009277 at gmail dot com
2013-06-24  7:49 ` [Bug c++/57693] " pinskia at gcc dot gnu.org
2013-06-24  8:15 ` vlad94009277 at gmail dot com
2013-06-24  8:18 ` jakub at gcc dot gnu.org
2013-06-24 10:05 ` manu at gcc dot gnu.org

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).