public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/50142] New: There is bug when swap elements of an array via chain expression.
@ 2011-08-21 11:38 thomas.c.zhao at gmail dot com
  2011-08-21 12:01 ` [Bug c/50142] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: thomas.c.zhao at gmail dot com @ 2011-08-21 11:38 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50142
           Summary: There is bug when swap elements of an array via chain
                    expression.
    Classification: Unclassified
           Product: gcc
           Version: 4.0.3
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: thomas.c.zhao@gmail.com


[gcc version]: 4.0.3
[system type]: sparc-sun-solaris2.10
[build options]: none
[source code]:
main()
{
 int a[] = {1,2};
 a[0] ^= a[1] ^= a[0] ^= a[1];
 printf("a[0]=%d a[1]=%d\n", a[0], a[1]);
}

[expected result]: a[0]=2 a[1]=1
[actual result]: a[0]=0 a[1]=1

btw: gcc3 is ok.


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

* [Bug c/50142] There is bug when swap elements of an array via chain expression.
  2011-08-21 11:38 [Bug c/50142] New: There is bug when swap elements of an array via chain expression thomas.c.zhao at gmail dot com
@ 2011-08-21 12:01 ` rguenth at gcc dot gnu.org
  2011-08-22  3:33 ` thomas.c.zhao at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-08-21 12:01 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

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

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-21 11:54:44 UTC ---
Evaluation order is undefined since there is no sequence point involved.


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

* [Bug c/50142] There is bug when swap elements of an array via chain expression.
  2011-08-21 11:38 [Bug c/50142] New: There is bug when swap elements of an array via chain expression thomas.c.zhao at gmail dot com
  2011-08-21 12:01 ` [Bug c/50142] " rguenth at gcc dot gnu.org
@ 2011-08-22  3:33 ` thomas.c.zhao at gmail dot com
  2011-08-22  6:47 ` jakub at gcc dot gnu.org
  2011-08-22  8:11 ` thomas.c.zhao at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: thomas.c.zhao at gmail dot com @ 2011-08-22  3:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from ZHAO Xiaogang <thomas.c.zhao at gmail dot com> 2011-08-22 00:36:34 UTC ---
(In reply to comment #1)
> Evaluation order is undefined since there is no sequence point involved.

I don't think so.
The associativity of operator ^= is Right to Left.

I have build the code with other compiler.
gcc 3.x is OK.
Sun cc is OK.
Microsoft VC is OK.

If there isn't any array, it's also OK when use gcc4 build.
main()
{
 int a = 1, b = 2;
 a ^= b ^= a ^= b;
 printf("a=%d b=%d\n", a, b);
}

[expected result]: a=2 b=1
[actual result]: a=2 b=1

So, I guess, the defect associated with the gcc4 new feature which optimized
array access.


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

* [Bug c/50142] There is bug when swap elements of an array via chain expression.
  2011-08-21 11:38 [Bug c/50142] New: There is bug when swap elements of an array via chain expression thomas.c.zhao at gmail dot com
  2011-08-21 12:01 ` [Bug c/50142] " rguenth at gcc dot gnu.org
  2011-08-22  3:33 ` thomas.c.zhao at gmail dot com
@ 2011-08-22  6:47 ` jakub at gcc dot gnu.org
  2011-08-22  8:11 ` thomas.c.zhao at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-08-22  6:47 UTC (permalink / raw)
  To: gcc-bugs

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

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> 2011-08-22 06:06:29 UTC ---
You are wrong, please read the standard, in particular ISO C99 5.1.2.3 and
Annex C.


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

* [Bug c/50142] There is bug when swap elements of an array via chain expression.
  2011-08-21 11:38 [Bug c/50142] New: There is bug when swap elements of an array via chain expression thomas.c.zhao at gmail dot com
                   ` (2 preceding siblings ...)
  2011-08-22  6:47 ` jakub at gcc dot gnu.org
@ 2011-08-22  8:11 ` thomas.c.zhao at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: thomas.c.zhao at gmail dot com @ 2011-08-22  8:11 UTC (permalink / raw)
  To: gcc-bugs

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

ZHAO Xiaogang <thomas.c.zhao at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |trivial

--- Comment #4 from ZHAO Xiaogang <thomas.c.zhao at gmail dot com> 2011-08-22 07:59:45 UTC ---
(In reply to comment #3)
> You are wrong, please read the standard, in particular ISO C99 5.1.2.3 and
> Annex C.
I understand.
Thanks.


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

end of thread, other threads:[~2011-08-22  8:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-21 11:38 [Bug c/50142] New: There is bug when swap elements of an array via chain expression thomas.c.zhao at gmail dot com
2011-08-21 12:01 ` [Bug c/50142] " rguenth at gcc dot gnu.org
2011-08-22  3:33 ` thomas.c.zhao at gmail dot com
2011-08-22  6:47 ` jakub at gcc dot gnu.org
2011-08-22  8:11 ` thomas.c.zhao at gmail dot com

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