public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenther at suse dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
Date: Wed, 06 Oct 2010 20:57:00 -0000	[thread overview]
Message-ID: <20101006205700.Iz8cmiJpHdAQxMkkkzKmEq95Ri-S5Q7DtaKr42vmb9Y@z> (raw)
In-Reply-To: <bug-41874-4@http.gcc.gnu.org/bugzilla/>

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.


  parent reply	other threads:[~2010-10-06 20:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-41874-4@http.gcc.gnu.org/bugzilla/>
2010-10-05  0:11 ` muravev at yandex dot ru
2010-10-05  4:49 ` fw at gcc dot gnu.org
2010-10-06 19:44 ` muravev at yandex dot ru
2010-10-06 20:57 ` rguenther at suse dot de [this message]
2012-10-15  9:27 ` paolo.carlini at oracle dot com
2012-10-15  9:45 ` rguenth at gcc dot gnu.org
2022-01-08 10:49 ` pinskia at gcc dot gnu.org
2022-12-03 22:03 ` jason at gcc dot gnu.org
2009-10-30  1:32 [Bug c++/41874] New: " jyasskin at gmail dot com
2009-11-06  9:09 ` [Bug c++/41874] " pinskia at gcc dot gnu dot org
2009-11-06  9:16 ` rguenther at suse dot de
2009-11-06  9:19 ` pinskia at gcc dot gnu dot org
2009-11-06  9:20 ` rguenth at gcc dot gnu dot org
2010-01-31  9:38 ` fw at deneb dot enyo dot de
2010-01-31 11:18 ` rguenth at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101006205700.Iz8cmiJpHdAQxMkkkzKmEq95Ri-S5Q7DtaKr42vmb9Y@z \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).