c/9902: optimization level -O2/3 doesn't work correctly.

gennadi.f@corigin.com gennadi.f@corigin.com
Sun Mar 2 16:26:00 GMT 2003


>Number:         9902
>Category:       c
>Synopsis:       optimization level -O2/3 doesn't work correctly.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Mar 02 16:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     gennadi.f@corigin.com
>Release:        3.2.2
>Organization:
>Environment:
sunOS 2.8 sparc
>Description:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
 char *page,*p;

 page=calloc(1,4);
 page+=4;
 p=page;
 if (page) { // if we change "page" here to "1", the result will be correct
     *((char **)page-1)=page;    // save the address in its previous 4 bytes.
     (*((char ***)page-1))++;    // add 4 to the saved address.
 }
 page=*((char **)page-1);        //"page" should be assigned to the new value.
 printf("page=%08X p=%08X\n",page,p); // with the optimization level -O2/3, the value of page i
s not changed.
 return 0;
}
>How-To-Repeat:
compile with and without O3/O2 options. 
>Fix:

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



More information about the Gcc-bugs mailing list