Hi, I'm not sure if this is a bug or I am just misunderstanding the attribute. First of all I noticed this behaviour on the following gcc version, but not earlier gcc (probably 4.2, I can't remember exactly):
Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.5.2-8ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.5 --enable-shared --enable-multiarch --with-multiarch-defaults=x86_64-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/x86_64-linux-gnu --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/x86_64-linux-gnu --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-gold --enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) My problem is that I have a library function which implements a memory allocator: 1. void *foo_alloc(size_t) __attribute__((malloc)); And a caller which does: 2. int *foo; 3. foo = foo_alloc(sizeof(int)); 4. *foo = bar; Then later on I have some code which walks the list of objects created by foo_alloc() and I find that they are uninitialised. Specifically line 4 of my example has been eliminated. >From the docs: The `malloc' attribute is used to tell the compiler that a function may be treated as if any non-`NULL' pointer it returns cannot alias any other pointer valid when the function returns. So AIUI, the optimiser has made a mistake, since "no alias *at the time* of function return" does not mean "no other alias EVER". I can produce a minimal example program if required. Thanks Gianni