http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41874

--- Comment #10 from rguenther at suse dot de <rguenther at suse dot de> 
2010-10-06 20:56:56 UTC ---
On Wed, 6 Oct 2010, muravev at yandex dot ru wrote:

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41874
> 
> --- Comment #9 from Ilya Murav'jov <muravev at yandex dot ru> 2010-10-06 
> 19:43:30 UTC ---
> I've come across another weird warning emission in g++ 4.4:
> 
> $ cat test.cc
> #include <new>
> struct interface_type {
> 
>     virtual interface_type* clone(void* storage) const
>     {
>         return ::new (storage) interface_type();
>     }
> };
> 
> struct poly_base {
> 
>     poly_base(const interface_type& x) { x.clone(data); }
> 
>     typedef char storage_t[100];
>     storage_t data;
> };
> 
> struct instance_t: interface_type {};
> 
> int main()
> {
>     instance_t pi;
>     poly_base p1(pi);
> 
>     interface_type* ptr = (interface_type*)(p1.data);
>     poly_base p2(*ptr);
> }
> $ g++ -O3 -Wstrict-aliasing test.cc -o /dev/null
> test.cc: In function ‘int main()’:
> test.cc:12: warning: dereferencing pointer ‘ptr’ does break strict-aliasing
> rules
> test.cc:25: note: initialized from here
> 
> $ g++ -v
> Using built-in specs.
> Target: i486-linux-gnu
> Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.1-4ubuntu9'
> --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
> --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
> --enable-multiarch --enable-linker-build-id --with-system-zlib
> --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
> --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls
> --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc
> --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic
> --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
> --target=i486-linux-gnu
> Thread model: posix
> gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9)
> 
> I get this only in g++ 4.4, g++ 4.5 does not warn.
> 
> I want to note that this is a different type of warning about strict-aliasing
> rules, likely a more serious one. Can anyone tell what a difference between
> "warning: dereferencing type-punned pointer will break strict-aliasing rules"
> and "warning: dereferencing pointer ‘ptr’ does break strict-aliasing rules"?

The latter means that when doing pointer analysis GCC pruned all 
pointed-to objects using TBAA so the pointer ended up pointing to
nothing (but still was dereferenced).  The good news for you is that
GCC will assume the pointer points to anything in that case, not
nothing.

In GCC 4.5 points-to analysis doesn't use TBAA to prune the sets anymore
(because its fundamentally wrong), so the code emitting the warning
was removed.

Richard.

Reply via email to