optimization/8302: Pointer casting causes ++ to be ignored when optimizing

noaml@mainsoft.com noaml@mainsoft.com
Mon Oct 21 09:46:00 GMT 2002


>Number:         8302
>Category:       optimization
>Synopsis:       Pointer casting causes ++ to be ignored when optimizing
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 21 09:46:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Noam Lampert
>Release:        gcc version 3.3 20021019 (experimental)
>Organization:
>Environment:
Intel 386. RH 7.3. kernel 2.4.18-3
>Description:
unsigned char *p;
unsigned char x;
....
*(*((unsigned char **)(&p)))++ = x;
as a side effect, p should be incremented. Sometimes, in optimized, it is not.
>How-To-Repeat:
gcc -O2 main.c
a.out
This source is in standard testcase format, and will call abort() upon failure.
>Fix:
Changing the code to 
*(*((unsigned char **)(&p))) = x;
p += sizeof(x);

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



More information about the Gcc-bugs mailing list