public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
       [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
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: muravev at yandex dot ru @ 2010-10-05  0:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Ilya Murav'jov <muravev at yandex dot ru> 2010-10-05 00:10:20 UTC ---
AFAIK, users of Boost.Function suffer from this PR too.
https://svn.boost.org/trac/boost/ticket/4538


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
       [not found] <bug-41874-4@http.gcc.gnu.org/bugzilla/>
  2010-10-05  0:11 ` [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning 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
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: fw at gcc dot gnu.org @ 2010-10-05  4:49 UTC (permalink / raw)
  To: gcc-bugs

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

Florian Weimer <fw at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fw at gcc dot gnu.org

--- Comment #8 from Florian Weimer <fw at gcc dot gnu.org> 2010-10-05 04:48:54 UTC ---
(In reply to comment #6)

> The general problem is that alias analysis is hard, thus follows that proper
> warnings are equally hard.

Note that it says "will break strict-aliasing rules", not "might break
strict-aliasing rules" (which also exists). I think the user can reasonably
expect that the "will break" variant is actually true.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
       [not found] <bug-41874-4@http.gcc.gnu.org/bugzilla/>
  2010-10-05  0:11 ` [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning 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
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: muravev at yandex dot ru @ 2010-10-06 19:44 UTC (permalink / raw)
  To: gcc-bugs

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"?


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
       [not found] <bug-41874-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2010-10-06 19:44 ` muravev at yandex dot ru
@ 2010-10-06 20:57 ` rguenther at suse dot de
  2012-10-15  9:27 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: rguenther at suse dot de @ 2010-10-06 20:57 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
       [not found] <bug-41874-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2010-10-06 20:57 ` rguenther at suse dot de
@ 2012-10-15  9:27 ` paolo.carlini at oracle dot com
  2012-10-15  9:45 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-10-15  9:27 UTC (permalink / raw)
  To: gcc-bugs


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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|gcc-bugs at gcc dot gnu.org |

--- Comment #11 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-10-15 09:27:13 UTC ---
Richard, is this still an issue?


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
       [not found] <bug-41874-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  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
  7 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-10-15  9:45 UTC (permalink / raw)
  To: gcc-bugs


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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.0

--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> 2012-10-15 09:45:11 UTC ---
No, the warning is gone from all releases that are still maintained.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
       [not found] <bug-41874-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  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
  7 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-08 10:49 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.5.0                       |---

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
       [not found] <bug-41874-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2022-01-08 10:49 ` pinskia at gcc dot gnu.org
@ 2022-12-03 22:03 ` jason at gcc dot gnu.org
  7 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2022-12-03 22:03 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |6.5.0
                 CC|                            |jason at gcc dot gnu.org
      Known to work|                            |7.5.0
   Target Milestone|---                         |7.0
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #17 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Aso Renji from comment #15)
> No, this warning still appear if (and only if) you use -O2 or -O3
> optimization key (as it be in startpost with "g++ -O3 -Wstrict-aliasing
> test.cc -o /dev/null" line).

I don't see this with any compiler after 6.5.0.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
  2009-10-30  1:32 [Bug c++/41874] New: " jyasskin at gmail dot com
                   ` (4 preceding siblings ...)
  2010-01-31  9:38 ` fw at deneb dot enyo dot de
@ 2010-01-31 11:18 ` rguenth at gcc dot gnu dot org
  5 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-01-31 11:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2010-01-31 11:17 -------
(In reply to comment #5)
> Isn't this a wrong-code bug?  Or is the information used for the diagnostic not
> used by the optimizers?

The diagnostics are independent on the optimizers, the one diagnostic that
isn't (that is emitted from the optimizer itself) causes the optimizer to
not optimize (well, because it saw the problem and thus there is no point
in breaking things just because we can).

The general problem is that alias analysis is hard, thus follows that proper
warnings are equally hard.  All warnings we emit are either possible false
positives or if they are not the optimizers will not miscompile your code
because they know there is an alias even though type-based analysis says
there is not (well, this is exactly the case you want to warn about, but
as analysis is hard once you can tell you can as well not exploit the
mis-optimization opportunity).


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
  2009-10-30  1:32 [Bug c++/41874] New: " jyasskin at gmail dot com
                   ` (3 preceding siblings ...)
  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
  5 siblings, 0 replies; 14+ messages in thread
From: fw at deneb dot enyo dot de @ 2010-01-31  9:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from fw at deneb dot enyo dot de  2010-01-31 09:38 -------
Isn't this a wrong-code bug?  Or is the information used for the diagnostic not
used by the optimizers?


-- 

fw at deneb dot enyo dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fw at deneb dot enyo dot de


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
  2009-10-30  1:32 [Bug c++/41874] New: " jyasskin at gmail dot com
                   ` (2 preceding siblings ...)
  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
  5 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-11-06  9:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2009-11-06 09:20 -------
Btw, this warning is emitted from the frontend which only warns if it sees
the address of an object casted, not random pointers (because of the
many false positives).  The frontend code also has no idea of the concept
of a dynamic type.


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
  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
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-11-06  9:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2009-11-06 09:18 -------
> > ------- Comment #1 from pinskia at gcc dot gnu dot org  2009-11-06 09:09 -------
> > 4.5 also fails 

Fails in that it warns still.

The first example warns with 4.5, while adding an extra variable and doing a
cast to void* causes GCC not to warn.  


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
  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
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 14+ messages in thread
From: rguenther at suse dot de @ 2009-11-06  9:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenther at suse dot de  2009-11-06 09:16 -------
Subject: Re:  Incorrect "dereferencing type-punned pointer
 will break strict-aliasing rules" warning

On Fri, 6 Nov 2009, pinskia at gcc dot gnu dot org wrote:

> ------- Comment #1 from pinskia at gcc dot gnu dot org  2009-11-06 09:09 -------
> 4.5 also fails and I cannot figure why if I do:

"fails"?

> #include <new>
> struct APInt {
>     int i;
> };
> int main() {
>     APInt I;
>     void *d;
>     char Data[sizeof(APInt)];
>     new((void*)Data)APInt();
>     d = Data;
>     *(APInt*)d = I;
> }
> 
> GCC does not warn.

Of course not - the code is perfectly valid (apart from Data
not having suitable alignment for APInt, but that's unrelated
to aliasing issues).

Richard.


-- 


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
  2009-10-30  1:32 [Bug c++/41874] New: " jyasskin at gmail dot com
@ 2009-11-06  9:09 ` pinskia at gcc dot gnu dot org
  2009-11-06  9:16 ` rguenther at suse dot de
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-11-06  9:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2009-11-06 09:09 -------
4.5 also fails and I cannot figure why if I do:
#include <new>
struct APInt {
    int i;
};
int main() {
    APInt I;
    void *d;
    char Data[sizeof(APInt)];
    new((void*)Data)APInt();
    d = Data;
    *(APInt*)d = I;
}

GCC does not warn.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
      Known to fail|                            |4.5.0
   Last reconfirmed|0000-00-00 00:00:00         |2009-11-06 09:09:42
               date|                            |


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


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-12-03 22:03 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-41874-4@http.gcc.gnu.org/bugzilla/>
2010-10-05  0:11 ` [Bug c++/41874] Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning 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
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

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).