Is this an optimizer bug?

From: Kasper Dupont (kasperd_at_daimi.au.dk)
Date: 05/31/05


Date: Tue, 31 May 2005 09:19:59 +0200

If I compile this program with -O2, the write statement
is executed only once. If I compile it with -O1 the write
statement is executed multiple times as expected.

Looks like an optimizer bug to me. Did I miss something?

I'm running FC1 with kernel version 2.4.22-1.2199.nptl
and gcc version 3.3.2-1.

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>

#define PAGESIZE (1<<12)
#define PAGES (1<<18)

int main()
{
  int i;
  char *mem;
  mem=mmap(NULL,PAGESIZE*PAGES,PROT_READ|PROT_WRITE,
           MAP_PRIVATE|MAP_ANONYMOUS,0,0);
  if (mem==MAP_FAILED) {
    perror("mmap");
    return EXIT_FAILURE;
  }

  for (i=0;i<PAGES;++i)
    if (write(1,mem+i*PAGESIZE,PAGESIZE)<1) {
      perror("write");
      return EXIT_FAILURE;
    }

  return 0;
}

-- 
Kasper Dupont -- der bruger for meget tid på usenet.
Note to self: Don't try to allocate 256000 pages
with GFP_KERNEL on x86.


Relevant Pages

  • Re: GCC difference in size of long int on Suse SLES9 / Suse Professional 10.0
    ... The kernel uses printf() with 'long int', ... I can't compile 'on-the-fly'. ... clashing with the hardware and any libs that you interact with. ... platform types build up their own int types. ...
    (comp.os.linux.development.apps)
  • Re: Im a C++ programmer, and Relfs X.CPP is good.
    ... >> and it doesn't compile either. ... home.cpp:93: implicit declaration of function `int fclose' ... You cannot change to your home directory through an external ...
    (comp.lang.lisp)
  • Re: Im a C++ programmer, and Relfs X.CPP is good.
    ... >> and it doesn't compile either. ... home.cpp:93: implicit declaration of function `int fclose' ... You cannot change to your home directory through an external ...
    (comp.unix.programmer)
  • Re: new order doubt
    ... Warning test2.c: 8 no type specified. ... Defaulting to int ... Tests probably come in several different types: this should compile ... Even Microsoft has problems with this obscure rules. ...
    (comp.lang.c)
  • Re: non-static context
    ... public MyStatic(int length, int width) { ... Within the MyStatic constructor method, a local variable named area is ... This version of class MyStatic won't compile. ...
    (comp.lang.java.help)