Bug 9902 - optimization level -O2/3 doesn't work correctly.
Summary: optimization level -O2/3 doesn't work correctly.
Status: RESOLVED DUPLICATE of bug 9901
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.2.2
: P3 normal
Target Milestone: ---
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-03-02 16:26 UTC by gennadi.f
Modified: 2003-06-12 00:15 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gennadi.f 2003-03-02 16:26:00 UTC
#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;
}

Release:
3.2.2

Environment:
sunOS 2.8 sparc

How-To-Repeat:
compile with and without O3/O2 options.
Comment 1 Paolo Carlini 2003-03-02 16:43:26 UTC
*** This bug has been marked as a duplicate of 9901 ***
Comment 2 Paolo Carlini 2003-03-02 17:03:38 UTC
State-Changed-From-To: closed->open
State-Changed-Why: Closed as a duplicate by mistake.
Comment 3 Eric Botcazou 2003-03-14 15:48:30 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Not a bug. Your code breaks the ISO C aliasing rules. GCC
    automatically turns on -fstrict-aliasing at -O2 so you need
    to fix your code or compile it with -fno-strict-aliasing.