gcc-4.4 optimization of a program using -O3 leads to incorrect assembly code
Issue
- gcc-4.4 optimization of a program using -O3 leads to incorrect assembly code
- The program is as follows:
#include <stdlib.h>
typedef struct bmRecord bmRecord;
struct bmRecord {
bmRecord *next;
};typedef struct bmHeader bmhdr;
struct bmHeader {
void *blocklist;
bmRecord *freelist;int
nrec,
datasize,
realsize,
blocksize;
};typedef struct {
int x;
int y;
} vPoint;typedef struct varPoint varPoint;
struct varPoint {
varPoint *next;
vPoint point;
};typedef struct varShape varShape;
struct varShape {
varShape *next;
varPoint *points;
int nPoints;
};static bmhdr VarPointPool;
int getShape(void *inPtr, int *layer, int *nPoints, vPoint **points)
{
static vPoint tmpPoints[4096];
varPoint *p, *nextP;
varShape *s, **inShapes = inPtr;*layer = *nPoints = 0;
s = *inShapes;
if( !s ) return 1;*points = (vPoint*) tmpPoints;
for( p = s->points; p; p = nextP ) {
tmpPoints[(*nPoints)++] = p->point;
nextP = p->next;
{
bmRecord *bm__y;
bmhdr *bm__z;bm__z = &(VarPointPool);
bm__y = (bmRecord *) (void *)(p);
bm__y->next = bm__z->freelist;
bm__z->freelist = bm__y;
}
}
*inShapes = s->next;
return 1;
}int call_getShape(void)
{
varShape inPtr1, *inPtr = &inPtr1;
int layer=0, nPoints=0;
vPoint *pouts[1024];
varPoint *points = (varPoint *)calloc(1,sizeof(varPoint));inPtr->points = points;
points->next = (varPoint *)calloc(1, sizeof(varPoint));
points->next->next = 0;VarPointPool.freelist = (bmRecord *)0x100;
getShape( &inPtr, &layer, &nPoints, &pouts[0]);return 0;
}int main(int argc, char *argv[])
{
call_getShape();
return 0;
}
Environment
- Red Hat Enterprise Linux 5.5
- gcc44
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
