public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/42032]  New: Aliasing errors in stl_tree.h
@ 2009-11-13 19:23 craig dot schlenter at gmail dot com
  2009-11-13 19:25 ` [Bug c++/42032] " pinskia at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 13+ messages in thread
From: craig dot schlenter at gmail dot com @ 2009-11-13 19:23 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2198 bytes --]

I'm seeing the following error:

In function ‘int main()’:
cc1plus: warning: dereferencing pointer ‘<anonymous>’ does break
strict-aliasing
rules
/usr/lib/gcc/i386-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_tree.h:184:
note: initialized from here

I'm unsure of these are legitimate warnings i.e. if stl_tree.h is genuinely
faulty or if it's a false positive from g++. This appears to be similar to
issue 39207.

This problem was originally encountered in chromium (dev.chromium.org) but I
have produced a much reduced test case below. I'm not expecting the reduced
test case to run of course but compilation would be nice :)

Compile with -O2 -Wall

[begin main.cc]

#include <list>
#include <map>

class MyClass {
 public:
  typedef std::list<int> MyList;
  typedef std::map<int, MyList::iterator> MyMap;

  MyClass() {}
  ~MyClass() {}

  void Fail(const int key) {
    MyMap::iterator map_iter = map_.find(key);
    // this doesn't fail
    MyList::iterator list_iter = map_iter->second;
    // this does
    list_.erase(map_iter->second);
  }

  MyList list_;
  MyMap map_;
};


int main(void)
{
  MyClass myclass;

  myclass.Fail(5);

  return 0;
}

[end main.cc]

Please let me know if you need a save-temps version too.

Thank you!

$ gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran --disable-libgcj
--with-tune=generic --with-arch=i586 --build=i386-redhat-linux
Thread model: posix
gcc version 4.4.0 20090310 (Red Hat 4.4.0-0.24) (GCC)


-- 
           Summary: Aliasing errors in stl_tree.h
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: craig dot schlenter at gmail dot com


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


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

* [Bug c++/42032] Aliasing errors in stl_tree.h
  2009-11-13 19:23 [Bug c++/42032] New: Aliasing errors in stl_tree.h craig dot schlenter at gmail dot com
@ 2009-11-13 19:25 ` pinskia at gcc dot gnu dot org
  2009-11-13 19:34 ` craig dot schlenter at gmail dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-11-13 19:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2009-11-13 19:25 -------
Might be related to PR 39390.


-- 


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


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

* [Bug c++/42032] Aliasing errors in stl_tree.h
  2009-11-13 19:23 [Bug c++/42032] New: Aliasing errors in stl_tree.h craig dot schlenter at gmail dot com
  2009-11-13 19:25 ` [Bug c++/42032] " pinskia at gcc dot gnu dot org
@ 2009-11-13 19:34 ` craig dot schlenter at gmail dot com
  2009-11-13 19:49 ` evan at chromium dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: craig dot schlenter at gmail dot com @ 2009-11-13 19:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from craig dot schlenter at gmail dot com  2009-11-13 19:34 -------
(In reply to comment #1)
> Might be related to PR 39390.

Would it be possible for someone to test the code from the description section
with trunk please .. if error messages were removed, the problem should be gone
:) I unfortunately don't have easy access to a more modern gcc than 4.4.0 to
test with.

Thank you.


-- 


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


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

* [Bug c++/42032] Aliasing errors in stl_tree.h
  2009-11-13 19:23 [Bug c++/42032] New: Aliasing errors in stl_tree.h craig dot schlenter at gmail dot com
  2009-11-13 19:25 ` [Bug c++/42032] " pinskia at gcc dot gnu dot org
  2009-11-13 19:34 ` craig dot schlenter at gmail dot com
@ 2009-11-13 19:49 ` evan at chromium dot org
  2009-11-13 19:54 ` rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: evan at chromium dot org @ 2009-11-13 19:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from evan at chromium dot org  2009-11-13 19:49 -------
I brought this up on the Google-internal C list.  They reduced it further:

$ cat main.cc
#include <map>

int main(void)
{
   typedef std::map<int, char*> MyMap2;
   MyMap2 map2_;
   MyMap2::iterator map_iter2 = map2_.find(5);
   return *map_iter2->second;
}
$ g++ -O3 -Wall -c main.cc
main.cc: In function 'int main()':
main.cc:8: warning: dereferencing pointer '<anonymous>' does break
strict-aliasing rules
/opt/local/include/gcc44/c++/bits/stl_tree.h:179: note: initialized from here

$ g++ -v
Using built-in specs.
Target: i386-apple-darwin9
Configured with: ../gcc-4.4.1/configure --prefix=/opt/local
--build=i386-apple-darwin9
--enable-languages=c,c++,objc,obj-c++,java,fortran
--libdir=/opt/local/lib/gcc44 --includedir=/opt/local/include/gcc44
--infodir=/opt/local/share/info --mandir=/opt/local/share/man
--with-local-prefix=/opt/local --with-system-zlib --disable-nls
--program-suffix=-mp-4.4
--with-gxx-include-dir=/opt/local/include/gcc44/c++/
--with-gmp=/opt/local --with-mpfr=/opt/local
Thread model: posix
gcc version 4.4.1 (GCC)


-- 

evan at chromium dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |evan at chromium dot org


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


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

* [Bug c++/42032] Aliasing errors in stl_tree.h
  2009-11-13 19:23 [Bug c++/42032] New: Aliasing errors in stl_tree.h craig dot schlenter at gmail dot com
                   ` (2 preceding siblings ...)
  2009-11-13 19:49 ` evan at chromium dot org
@ 2009-11-13 19:54 ` rguenth at gcc dot gnu dot org
  2009-11-13 20:03 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-11-13 19:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2009-11-13 19:54 -------
It may be related to PR41316, I suspected that the library might contain
similar patterns in other containers besides forward_list.


-- 


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


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

* [Bug c++/42032] Aliasing errors in stl_tree.h
  2009-11-13 19:23 [Bug c++/42032] New: Aliasing errors in stl_tree.h craig dot schlenter at gmail dot com
                   ` (3 preceding siblings ...)
  2009-11-13 19:54 ` rguenth at gcc dot gnu dot org
@ 2009-11-13 20:03 ` rguenth at gcc dot gnu dot org
  2009-11-13 20:52 ` paolo dot carlini at oracle dot com
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-11-13 20:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2009-11-13 20:02 -------
There are definitely a lot of casts like

  static_cast<_Link_type>(_M_node)

in stl_list.h.  If _M_node is ever not a rb_tree_node but only a
rb_tree_node_base
(which probably is the case again for the head of the tree) then this is an
alias violation.

Note that 4.5 will no longer warn for this because I removed the warning code
as it wasn't aware of the concept of C++ dynamic types and thus lead to many
false positives.  There is no replacement for it, so you'll need to do code
review to catch all cases.


-- 


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


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

* [Bug c++/42032] Aliasing errors in stl_tree.h
  2009-11-13 19:23 [Bug c++/42032] New: Aliasing errors in stl_tree.h craig dot schlenter at gmail dot com
                   ` (4 preceding siblings ...)
  2009-11-13 20:03 ` rguenth at gcc dot gnu dot org
@ 2009-11-13 20:52 ` paolo dot carlini at oracle dot com
  2009-11-16  4:38 ` craig dot schlenter at gmail dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 13+ messages in thread
From: paolo dot carlini at oracle dot com @ 2009-11-13 20:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from paolo dot carlini at oracle dot com  2009-11-13 20:51 -------
Note that, as far as I have been told by Richard, the warning itself doesn't
point to an actual miscompilation in 4.4, because (PRE, etc.) aren't strong
enough. Thus, first people should double check that, and in case we could
backport to 4.4. the warning suppression bits (in any case, that warnings are
emitted from system headers is a bug, per se).

Then, as regards mainline, we should, again, check whether actual
miscompilations are taking place, I'm not aware of any. At the time of PR41316,
I went quickly through the code and didn't find any problematic series of up
and down casts outside (the still very experimental, I'm working on it while we
are speaking) forward_list. 


-- 


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


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

* [Bug c++/42032] Aliasing errors in stl_tree.h
  2009-11-13 19:23 [Bug c++/42032] New: Aliasing errors in stl_tree.h craig dot schlenter at gmail dot com
                   ` (5 preceding siblings ...)
  2009-11-13 20:52 ` paolo dot carlini at oracle dot com
@ 2009-11-16  4:38 ` craig dot schlenter at gmail dot com
  2010-05-04 12:06 ` paolo dot carlini at oracle dot com
  2010-08-06  6:54 ` paolo dot carlini at oracle dot com
  8 siblings, 0 replies; 13+ messages in thread
From: craig dot schlenter at gmail dot com @ 2009-11-16  4:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from craig dot schlenter at gmail dot com  2009-11-16 04:37 -------
(In reply to comment #3)
> I brought this up on the Google-internal C list.  They reduced it further:
> 
> $ cat main.cc
> #include <map>
> 
> int main(void)
> {
>    typedef std::map<int, char*> MyMap2;
>    MyMap2 map2_;
>    MyMap2::iterator map_iter2 = map2_.find(5);
>    return *map_iter2->second;
> }
> $ g++ -O3 -Wall -c main.cc
> main.cc: In function 'int main()':
> main.cc:8: warning: dereferencing pointer '<anonymous>' does break
> strict-aliasing rules
> /opt/local/include/gcc44/c++/bits/stl_tree.h:179: note: initialized from here

Hironori Bono spotted btw. that if the key for the map is changed from an int
to a std::string, then the aliasing warning disappears:

#include <map>
#include <string>

int main(void)
{
  typedef std::map<std::string, char*> MyMap2;
  MyMap2 map2_;
  MyMap2::iterator map_iter2 = map2_.find("hello");
  return *map_iter2->second;
}

This is rather strange and confusing.


-- 


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


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

* [Bug c++/42032] Aliasing errors in stl_tree.h
  2009-11-13 19:23 [Bug c++/42032] New: Aliasing errors in stl_tree.h craig dot schlenter at gmail dot com
                   ` (6 preceding siblings ...)
  2009-11-16  4:38 ` craig dot schlenter at gmail dot com
@ 2010-05-04 12:06 ` paolo dot carlini at oracle dot com
  2010-08-06  6:54 ` paolo dot carlini at oracle dot com
  8 siblings, 0 replies; 13+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-05-04 12:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from paolo dot carlini at oracle dot com  2010-05-04 12:05 -------
*** Bug 43978 has been marked as a duplicate of this bug. ***


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |musiphil at bawi dot org


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


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

* [Bug c++/42032] Aliasing errors in stl_tree.h
  2009-11-13 19:23 [Bug c++/42032] New: Aliasing errors in stl_tree.h craig dot schlenter at gmail dot com
                   ` (7 preceding siblings ...)
  2010-05-04 12:06 ` paolo dot carlini at oracle dot com
@ 2010-08-06  6:54 ` paolo dot carlini at oracle dot com
  8 siblings, 0 replies; 13+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-08-06  6:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from paolo dot carlini at oracle dot com  2010-08-06 06:53 -------
*** Bug 45202 has been marked as a duplicate of this bug. ***


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eric_moyer at yahoo dot com


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


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

* [Bug c++/42032] Aliasing errors in stl_tree.h
       [not found] <bug-42032-4@http.gcc.gnu.org/bugzilla/>
  2011-09-25 16:04 ` paolo.carlini at oracle dot com
  2011-09-25 16:08 ` evan at chromium dot org
@ 2011-09-26 10:46 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-09-26 10:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #12 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-09-26 10:30:35 UTC ---
Nope.  Marking fixed in 4.5.


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

* [Bug c++/42032] Aliasing errors in stl_tree.h
       [not found] <bug-42032-4@http.gcc.gnu.org/bugzilla/>
  2011-09-25 16:04 ` paolo.carlini at oracle dot com
@ 2011-09-25 16:08 ` evan at chromium dot org
  2011-09-26 10:46 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 13+ messages in thread
From: evan at chromium dot org @ 2011-09-25 16:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Evan Martin <evan at chromium dot org> 2011-09-25 16:02:25 UTC ---
I am on personal leave until 2012.

If you're within Google, you can read http://www/~evanm/leave.html for more.

Otherwise, for Chrome questions you can try asking tony@chromium.org,
and for questions for me personally you can try martine@danga.com.


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

* [Bug c++/42032] Aliasing errors in stl_tree.h
       [not found] <bug-42032-4@http.gcc.gnu.org/bugzilla/>
@ 2011-09-25 16:04 ` paolo.carlini at oracle dot com
  2011-09-25 16:08 ` evan at chromium dot org
  2011-09-26 10:46 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-25 16:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #10 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-25 16:01:01 UTC ---
Richard, I don't think we want to keep this open, do we?


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

end of thread, other threads:[~2011-09-26 10:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-13 19:23 [Bug c++/42032] New: Aliasing errors in stl_tree.h craig dot schlenter at gmail dot com
2009-11-13 19:25 ` [Bug c++/42032] " pinskia at gcc dot gnu dot org
2009-11-13 19:34 ` craig dot schlenter at gmail dot com
2009-11-13 19:49 ` evan at chromium dot org
2009-11-13 19:54 ` rguenth at gcc dot gnu dot org
2009-11-13 20:03 ` rguenth at gcc dot gnu dot org
2009-11-13 20:52 ` paolo dot carlini at oracle dot com
2009-11-16  4:38 ` craig dot schlenter at gmail dot com
2010-05-04 12:06 ` paolo dot carlini at oracle dot com
2010-08-06  6:54 ` paolo dot carlini at oracle dot com
     [not found] <bug-42032-4@http.gcc.gnu.org/bugzilla/>
2011-09-25 16:04 ` paolo.carlini at oracle dot com
2011-09-25 16:08 ` evan at chromium dot org
2011-09-26 10:46 ` rguenth at gcc dot gnu.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).