This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

optimization/5186: -O works; -O2 doesn't; partial assignment through cast to smaller type



>Number:         5186
>Category:       optimization
>Synopsis:       -O works; -O2 doesn't; partial assignment through cast to smaller type
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 24 10:06:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Anthony J. Battersby
>Release:        gcc version 3.0.2 20010905 (Red Hat Linux 7.1 3.0.1-3)
>Organization:
>Environment:
RedHat Linux 7.2 i386 + latest errata updates
>Description:
The included small test program fails with -O2 but works with -O.  Note that the program assumes a little-endian architecture (i386).

The program does partial modification of a variable by casting its address to a pointer of a smaller type, and then reads back the entire value.

The first write to 'test' through the (char *) really should do nothing, but it is part of what triggers the bug.  Also, the bug is not triggered if the array index on this line is [0] rather than [1].

The same sort of thing happens when the partial assignment takes place in a function that is inlined.

I encountered the problem with RedHat's gcc-2.96-98, and then verified that the problem also exists in gcc-3.0.2.

>How-To-Repeat:
gcc3 -Wall -O -ogood gccbug.c
gcc3 --save-temps -Wall -O2 -obad gccbug.c
./good
(no output)
./bad
test failed: 0xaabbccdd
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]