public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: optimization/5186: -O works; -O2 doesn't; partial assignment through cast to smaller type
@ 2002-04-03  1:48 rth
  0 siblings, 0 replies; 2+ messages in thread
From: rth @ 2002-04-03  1:48 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, tonyb

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

State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Wed Apr  3 01:48:17 2002
State-Changed-Why:
    Not a bug.  This code violates ISO C aliasing rules.
    Use a union instead.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5186


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

* optimization/5186: -O works; -O2 doesn't; partial assignment through cast to smaller type
@ 2001-12-24 10:06 tonyb
  0 siblings, 0 replies; 2+ messages in thread
From: tonyb @ 2001-12-24 10:06 UTC (permalink / raw)
  To: gcc-gnats


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


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

end of thread, other threads:[~2002-04-03  9:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-03  1:48 optimization/5186: -O works; -O2 doesn't; partial assignment through cast to smaller type rth
  -- strict thread matches above, loose matches on Subject: below --
2001-12-24 10:06 tonyb

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