Monday, October 29, 2007

gcc optimizer

I found that the following code causes segfault when compiled with -O2. Compiler:
gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

#include <stdlib.h>

struct prime {
struct prime *next;
};

int main(){
struct prime primes = {.next=NULL};
struct prime *p = ℙ

while (p->next != NULL){
p = p->next;
}
p->next = (struct prime*) malloc (sizeof(struct prime));
return 0;
}

No comments: