Bug 156082 - gcc(1) makes incorrect code when swapping array elements by xor without optimization
Summary: gcc(1) makes incorrect code when swapping array elements by xor without optim...
Status: Closed Overcome By Events
Alias: None
Product: Base System
Classification: Unclassified
Component: gnu (show other bugs)
Version: 9.0-CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-31 09:50 UTC by Dmitry Afanasiev
Modified: 2015-01-22 16:11 UTC (History)
1 user (show)

See Also:


Attachments
file.txt (488 bytes, text/plain)
2011-03-31 09:50 UTC, Dmitry Afanasiev
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Afanasiev 2011-03-31 09:50:12 UTC
Base gcc 4.2.1 makes incorrect code when swapping array elements by xor without optimization.
Simple .c code attached as xor.txt.
Checked on FreeBSD 9.0 on i386/amd64/sparc64 platforms.

Fix: Patch attached with submission follows:
How-To-Repeat: # gcc -o xor xor.txt
# gcc -o xoro1 -O1 xor.txt
# ./xor
a0 = 127 b0 = 33
a1 = 127 b1 = 33
a2 = 127 b2[0] = 33
a3 = 127 b3[0] = 0
# ./xoro1
a0 = 127 b0 = 33
a1 = 127 b1 = 33
a2 = 127 b2[0] = 33
a3 = 127 b3[0] = 33

But in theory output must be identical.
Comment 1 Pedro F. Giffuni freebsd_committer freebsd_triage 2015-01-22 16:11:04 UTC
The bug is still present in FreeBSD 9.3's gcc. The bug is not present with the bundled clang though.

Unfortunately we don't plan to do major updates to the gcc version available in the FreeBSD 9.x series: 10.x and newer ship with clang by default. Please use clang or the gcc version from ports which should be a lot more up to date.