public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39121] strange behavior in chained operations
       [not found] <bug-39121-4@http.gcc.gnu.org/bugzilla/>
@ 2015-06-25 18:51 ` joe.carnuccio at qlogic dot com
  2015-06-25 19:10 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: joe.carnuccio at qlogic dot com @ 2015-06-25 18:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from joe.carnuccio at qlogic dot com ---
Since using gcc -Os causes the correct execution, then "sequence point" does
not have anything to do with it.


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

* [Bug c/39121] strange behavior in chained operations
       [not found] <bug-39121-4@http.gcc.gnu.org/bugzilla/>
  2015-06-25 18:51 ` [Bug c/39121] strange behavior in chained operations joe.carnuccio at qlogic dot com
@ 2015-06-25 19:10 ` pinskia at gcc dot gnu.org
  2015-06-25 19:40 ` joe.carnuccio at qlogic dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2015-06-25 19:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to joe.carnuccio from comment #5)
> Since using gcc -Os causes the correct execution, then "sequence point" does
> not have anything to do with it.

And you are wrong about that.  -Os causes what you think is the correct
execution but there are multiple interpretations of the code because there are
not sequence points there.


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

* [Bug c/39121] strange behavior in chained operations
       [not found] <bug-39121-4@http.gcc.gnu.org/bugzilla/>
  2015-06-25 18:51 ` [Bug c/39121] strange behavior in chained operations joe.carnuccio at qlogic dot com
  2015-06-25 19:10 ` pinskia at gcc dot gnu.org
@ 2015-06-25 19:40 ` joe.carnuccio at qlogic dot com
  2015-06-25 20:08 ` manu at gcc dot gnu.org
  2015-08-10  3:38 ` frankhb1989 at gmail dot com
  4 siblings, 0 replies; 8+ messages in thread
From: joe.carnuccio at qlogic dot com @ 2015-06-25 19:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from joe.carnuccio at qlogic dot com ---
Ok, the sequence points are at each of the assignment operators.

The crux of this is that doing the xor chain with dereferenced pointers fails
(incorrect execution), whereas doing it with variables works...

i.e. *a and *b are being treated differently than a and b;


a ^= b ^= a ^= b is supposed to do the following:

a = a ^ (b = b ^ (a = a ^ b))

from right-to-left each assignment is done in sequence (and has been verified
to work correctly);


*a ^= *b ^= *a ^= *b should work the same way, but it does not (unless you
compile with -Os).


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

* [Bug c/39121] strange behavior in chained operations
       [not found] <bug-39121-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2015-06-25 19:40 ` joe.carnuccio at qlogic dot com
@ 2015-06-25 20:08 ` manu at gcc dot gnu.org
  2015-08-10  3:38 ` frankhb1989 at gmail dot com
  4 siblings, 0 replies; 8+ messages in thread
From: manu at gcc dot gnu.org @ 2015-06-25 20:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #8 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to joe.carnuccio from comment #7)

> *a ^= *b ^= *a ^= *b should work the same way, but it does not (unless you
> compile with -Os).

https://gcc.gnu.org/wiki/FAQ#undefinedbut
>From gcc-bugs-return-490228-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jun 25 20:19:11 2015
Return-Path: <gcc-bugs-return-490228-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 58271 invoked by alias); 25 Jun 2015 20:19:10 -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 58223 invoked by uid 48); 25 Jun 2015 20:19:06 -0000
From: "manu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/66673] warning missing for undefined behavior when swapping variables via chained xor
Date: Thu, 25 Jun 2015 20:19:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 4.4.6
X-Bugzilla-Keywords:
X-Bugzilla-Severity: major
X-Bugzilla-Who: manu at gcc dot gnu.org
X-Bugzilla-Status: REOPENED
X-Bugzilla-Resolution:
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_status cf_reconfirmed_on cc resolution short_desc everconfirmed
Message-ID: <bug-66673-4-fFI7yC6Zej@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66673-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66673-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-06/txt/msg02560.txt.bz2
Content-length: 1626

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
   Last reconfirmed|                            |2015-06-25
                 CC|                            |manu at gcc dot gnu.org
         Resolution|INVALID                     |---
            Summary|swapping variables via      |warning missing for
                   |chained xor fails           |undefined behavior when
                   |                            |swapping variables via
                   |                            |chained xor
     Ever confirmed|0                           |1

--- Comment #7 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #6)
> (In reply to joe.carnuccio from comment #2)
> > -Wall produces no warnings...
> 
> Oh, you're using too old GCC.  Please try a newer version.

To be fair, GCC 5.1 does not generate a warning either with -Wall -Wextra.
Neither does clang 3.7.

For this testcase:

void swap(int *a, int *b) {
    *a ^= *b ^= *a ^= *b;
}

int main() {
    int a = 5;
    int b = 8;
    printf("%d, %d\n", a, b);
    a ^= b ^= a ^= b;
    __builtin_printf("%d, %d\n", a, b);
    swap(&a, &b);
    __builtin_printf("%d, %d\n", a, b);
}

Clang warns:
20 : warning: unsequenced modification and access to 'a' [-Wunsequenced]

a ^= b ^= a ^= b;

but gcc is silent.
>From gcc-bugs-return-490229-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jun 25 20:23:41 2015
Return-Path: <gcc-bugs-return-490229-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 75135 invoked by alias); 25 Jun 2015 20:23:41 -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 75054 invoked by uid 48); 25 Jun 2015 20:23:37 -0000
From: "manu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/66673] Wsequence-point warning missing when swapping variables via chained xor
Date: Thu, 25 Jun 2015 20:23:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords: diagnostic
X-Bugzilla-Severity: enhancement
X-Bugzilla-Who: manu at gcc dot gnu.org
X-Bugzilla-Status: REOPENED
X-Bugzilla-Resolution:
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: keywords version short_desc bug_severity
Message-ID: <bug-66673-4-iv0j6aME9V@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66673-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66673-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-06/txt/msg02561.txt.bz2
Content-length: 917

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
            Version|4.4.6                       |6.0
            Summary|warning missing for         |Wsequence-point warning
                   |undefined behavior when     |missing when swapping
                   |swapping variables via      |variables via chained xor
                   |chained xor                 |
           Severity|major                       |enhancement

--- Comment #8 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
It seems a missing feature to me. There are several open PRs about
Wsequence-point but this one does not seem to be one of them.
>From gcc-bugs-return-490230-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jun 25 20:26:23 2015
Return-Path: <gcc-bugs-return-490230-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 77744 invoked by alias); 25 Jun 2015 20:26:23 -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 77706 invoked by uid 48); 25 Jun 2015 20:26:19 -0000
From: "manu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/66673] Wsequence-point warning missing when swapping variables via chained xor
Date: Thu, 25 Jun 2015 20:26:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 6.0
X-Bugzilla-Keywords: diagnostic
X-Bugzilla-Severity: enhancement
X-Bugzilla-Who: manu at gcc dot gnu.org
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Resolution: FIXED
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_status resolution
Message-ID: <bug-66673-4-2b17kjUsZ8@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66673-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66673-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-06/txt/msg02562.txt.bz2
Content-length: 845

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #9 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
Ops, this may have been added recently, it does warn with my GCC 6 build:

test.c:2:6: warning: operation on ‘*a’ may be undefined [-Wsequence-point]
   *a ^= *b ^= *a ^= *b;
      ^
test.c:9:5: warning: operation on ‘a’ may be undefined [-Wsequence-point]
   a ^= b ^= a ^= b;
     ^

Oh, well, then this is INVALID. Sorry for the noise.
>From gcc-bugs-return-490231-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jun 25 20:35:30 2015
Return-Path: <gcc-bugs-return-490231-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 127992 invoked by alias); 25 Jun 2015 20:35:30 -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 127938 invoked by uid 48); 25 Jun 2015 20:35:27 -0000
From: "scovich at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/65656] __builtin_constant_p should always be constexpr
Date: Thu, 25 Jun 2015 20:35:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.8.3
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: scovich at gmail dot com
X-Bugzilla-Status: NEW
X-Bugzilla-Resolution:
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:
Message-ID: <bug-65656-4-H0pFCAm6ck@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-65656-4@http.gcc.gnu.org/bugzilla/>
References: <bug-65656-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-06/txt/msg02563.txt.bz2
Content-length: 613

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

--- Comment #3 from Ryan Johnson <scovich at gmail dot com> ---
(In reply to Jason Merrill from comment #2)
> Author: jason
> Date: Tue Apr 28 14:43:59 2015
> New Revision: 222531
> 
> URL: https://gcc.gnu.org/viewcvs?rev=222531&root=gcc&view=rev
> Log:
> 	PR c++/65656
> 	* constexpr.c (cxx_eval_builtin_function_call): Fix
> 	__builtin_constant_p.
> 
> Added:
>     trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-builtin3.C
> Modified:
>     trunk/gcc/cp/ChangeLog
>     trunk/gcc/cp/constexpr.c

Any reason this bug should not be closed as 'fixed' ?
>From gcc-bugs-return-490232-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jun 25 20:47:32 2015
Return-Path: <gcc-bugs-return-490232-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 82262 invoked by alias); 25 Jun 2015 20:47:32 -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 82218 invoked by uid 48); 25 Jun 2015 20:47:29 -0000
From: "huili80 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/66674] New: name lookup failure in lambda construction in a member function of a template class
Date: Thu, 25 Jun 2015 20:47:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.8.2
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: huili80 at gmail dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Resolution:
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 bug_severity priority component assigned_to reporter target_milestone
Message-ID: <bug-66674-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-06/txt/msg02564.txt.bz2
Content-length: 799

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

            Bug ID: 66674
           Summary: name lookup failure in lambda construction in a member
                    function of a template class
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: huili80 at gmail dot com
  Target Milestone: ---

The following causes internal compiler error with gcc4.8.2.

struct base
{
   void foo(){};
};

template < typename >
struct derived : base
{
   void foo()
   {
      auto l = [this](){base::foo();};
   // workaround:
   // auto l = [this](){this->base::foo();};
   };
};

int main()
{
   derived<int> d;
   d.foo();
}


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

* [Bug c/39121] strange behavior in chained operations
       [not found] <bug-39121-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2015-06-25 20:08 ` manu at gcc dot gnu.org
@ 2015-08-10  3:38 ` frankhb1989 at gmail dot com
  4 siblings, 0 replies; 8+ messages in thread
From: frankhb1989 at gmail dot com @ 2015-08-10  3:38 UTC (permalink / raw)
  To: gcc-bugs

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

frankhb1989 at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |frankhb1989 at gmail dot com

--- Comment #9 from frankhb1989 at gmail dot com ---
This should work since C++11 because the rules of builtin assignment were
modified (CWG 222; see also CWG 637). However, it is still undefined in C11,
even if the new "sequenced before" wording has been copied from C++11
(WG21/N1944).
Not sure if any diagnostics should be changed.


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

* [Bug c/39121] strange behavior in chained operations
  2009-02-06 19:40 [Bug c/39121] New: strange behavior of a chain of operations nospam at pamies dot cat
  2009-02-06 20:10 ` [Bug c/39121] strange behavior in chained operations pinskia at gcc dot gnu dot org
  2009-02-06 21:07 ` nospam at pamies dot cat
@ 2009-02-06 21:22 ` rguenth at gcc dot gnu dot org
  2 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-02-06 21:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2009-02-06 21:21 -------
Evaluation order is undefined if there is no sequence point.


-- 

rguenth at gcc dot gnu dot org changed:

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


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


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

* [Bug c/39121] strange behavior in chained operations
  2009-02-06 19:40 [Bug c/39121] New: strange behavior of a chain of operations nospam at pamies dot cat
  2009-02-06 20:10 ` [Bug c/39121] strange behavior in chained operations pinskia at gcc dot gnu dot org
@ 2009-02-06 21:07 ` nospam at pamies dot cat
  2009-02-06 21:22 ` rguenth at gcc dot gnu dot org
  2 siblings, 0 replies; 8+ messages in thread
From: nospam at pamies dot cat @ 2009-02-06 21:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from nospam at pamies dot cat  2009-02-06 21:07 -------
Is not the same bug as #15145. I agree with you that there is just one sequence
point, but the operation is not undefined.

void swap(int *a, int *b) {
    *a ^= *b ^= *a ^= *b;
}

This code should be compiled to:

*a = *a ^ *b;
*b = *b ^ *a;
*a = *a ^ *b;

And not to something like (I think that is what happens):

int tmp;
tmp = *a ^ *b;
*b = *b ^ tmp;
//On that point *a should contain 5^8 instead of the original value 5.
//This happens because the temp variable generated by the compiler.
*a = *a ^ *b;  

I think that the compiler is not translating properly what was written in the
source code. Summarizing, I think that in:

y = 1;
x = (y += 1);

The execution order should be:

volatile_register <--- y + 1
y                 <--- volatile_register
x                 <--- volatile_register

instead of:

volatile_register <--- y + 1
x                 <--- volatile_register
y                 <--- volatile_register


-- 

nospam at pamies dot cat changed:

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


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


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

* [Bug c/39121] strange behavior in chained operations
  2009-02-06 19:40 [Bug c/39121] New: strange behavior of a chain of operations nospam at pamies dot cat
@ 2009-02-06 20:10 ` pinskia at gcc dot gnu dot org
  2009-02-06 21:07 ` nospam at pamies dot cat
  2009-02-06 21:22 ` rguenth at gcc dot gnu dot org
  2 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-02-06 20:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2009-02-06 20:09 -------
This is undefined code as you are modifying *a twice without a sequence point
inbetween the modifies.

*** This bug has been marked as a duplicate of 15145 ***


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2015-08-10  3:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-39121-4@http.gcc.gnu.org/bugzilla/>
2015-06-25 18:51 ` [Bug c/39121] strange behavior in chained operations joe.carnuccio at qlogic dot com
2015-06-25 19:10 ` pinskia at gcc dot gnu.org
2015-06-25 19:40 ` joe.carnuccio at qlogic dot com
2015-06-25 20:08 ` manu at gcc dot gnu.org
2015-08-10  3:38 ` frankhb1989 at gmail dot com
2009-02-06 19:40 [Bug c/39121] New: strange behavior of a chain of operations nospam at pamies dot cat
2009-02-06 20:10 ` [Bug c/39121] strange behavior in chained operations pinskia at gcc dot gnu dot org
2009-02-06 21:07 ` nospam at pamies dot cat
2009-02-06 21:22 ` rguenth at gcc dot gnu dot 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).