[Bug c/39121] strange behavior in chained operations

2015-08-09 Thread frankhb1989 at gmail dot com
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.


[Bug c/39121] strange behavior in chained operations

2015-06-25 Thread manu at gcc dot gnu.org
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

[Bug c/39121] strange behavior in chained operations

2015-06-25 Thread joe.carnuccio at qlogic dot com
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).


[Bug c/39121] strange behavior in chained operations

2015-06-25 Thread joe.carnuccio at qlogic dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39121

joe.carnuccio at qlogic dot com changed:

   What|Removed |Added

 CC||joe.carnuccio at qlogic dot com

--- Comment #4 from joe.carnuccio at qlogic dot com ---
I have found the following:

This works: c ^= d ^= c ^= d  (where c and d are not pointers)

This fails: *a ^= *b ^= *a ^= *b  (where a and b are pointers)

When compiling using -Os then the failed case now works.


[Bug c/39121] strange behavior in chained operations

2015-06-25 Thread pinskia at gcc dot gnu.org
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.


[Bug c/39121] strange behavior in chained operations

2015-06-25 Thread joe.carnuccio at qlogic dot com
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.


[Bug c/39121] strange behavior in chained operations

2009-02-06 Thread pinskia at gcc dot gnu dot org


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



[Bug c/39121] strange behavior in chained operations

2009-02-06 Thread nospam at pamies dot cat


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



[Bug c/39121] strange behavior in chained operations

2009-02-06 Thread rguenth at gcc dot gnu dot org


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