public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53490] New: Segmentation Fault when accessing std::set
@ 2012-05-25 18:13 ja11sop at yahoo dot co.uk
  2012-05-25 18:22 ` [Bug c++/53490] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: ja11sop at yahoo dot co.uk @ 2012-05-25 18:13 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53490
           Summary: Segmentation Fault when accessing std::set
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ja11sop@yahoo.co.uk


The following g++ 4.7 compiled code, when executed on x86_64 Debian Sid,
segfaults.

The code is a reduced sample from a much larger code-base of production code
that ran ok with gcc4.6. With more time I could reduce it further but this
already consistently hits the problem and produces a useful back trace.

I have this as a blocker because all our application code essentially executes
something similar to this and so now all our applications segfault when built
with gcc4.7. Also I cannot come up with a trivial work-around without
re-writing large parts of the code base.

CODE:
//------------------------------------------------------------------

// Boost Library Includes
#include <boost/program_options.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/property_tree/ptree.hpp>

// C++ Standard Library Includes
#include <string>
#include <set>


typedef boost::property_tree::ptree                     property_tree_t;
typedef boost::shared_ptr<property_tree_t>              shared_property_tree_t;

void store_properties( int argc, const char* argv[] )
{
    typedef boost::program_options::options_description options_description_t;
    typedef boost::program_options::variables_map       variables_t;

    options_description_t Options( "Base Options" );
    Options.add_options()( "help,h", "Display Help" );

    variables_t Variables( new variables_t() );

    boost::program_options::parsed_options ParsedOptions = parse_command_line(
argc, argv, Options );
    boost::program_options::store( ParsedOptions, Variables );
    boost::program_options::notify( Variables );
}


typedef std::string                     string_t;
typedef std::set<string_t>              string_set_t;
typedef boost::shared_ptr<string_set_t> shared_string_set_t;

shared_string_set_t get_unique_keys( const string_t& Key, const
property_tree_t& PropertyTree )
{
    if( auto Children = PropertyTree.get_child_optional( Key ) )
    {
        shared_string_set_t Values( new string_set_t() );

        for( auto& Child : *Children )
        {
            // This line is required for the segfault
            Values->insert( Child.first );
        }
        return Values;
    }
    return shared_string_set_t();
}


int main( int argc, char* argv[] )
{
    const char* DummyArgv[] = { "std_set_bug_test", "--help", 0 };

    shared_property_tree_t PropertyTree =
boost::make_shared<property_tree_t>();

    store_properties( 2, DummyArgv );

    // No need to call this code
    //auto UniqueKeys = get_unique_keys( "log.sink", *PropertyTree );

    return 0;
}

//------------------------------------------------------------------

Code compiled with:

-Wall -g -std=c++11

Linked *statically* with the boost 1.49 program_options library.

BACKTRACE:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7933427 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
(gdb) bt
#0  0x00007ffff7933427 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1  0x000000000046412d in std::_Rb_tree_iterator<std::string>::operator--
(this=0x7fffffffdc60)
    at /usr/include/c++/4.7/bits/stl_tree.h:203
#2  0x0000000000462caa in std::pair<std::_Rb_tree_iterator<std::string>, bool>
std::_Rb_tree<std::string, std::string, std::_Identity<std::string>,
std::less<std::string>, std::allocator<std::string>
>::_M_insert_unique<std::string const&>(std::string const&) ()
#3  0x0000000000461b25 in std::set<std::string, std::less<std::string>,
std::allocator<std::string> >::insert(std::string const&) ()
#4  0x000000000047aeb1 in boost::program_options::store (options=..., xm=...,
utf8=false)
    at libs/program_options/src/variables_map.cpp:98
#5  0x0000000000460350 in store_properties(int, char const**) ()
#6  0x00000000004606ab in main ()
(gdb)


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

* [Bug c++/53490] Segmentation Fault when accessing std::set
  2012-05-25 18:13 [Bug c++/53490] New: Segmentation Fault when accessing std::set ja11sop at yahoo dot co.uk
@ 2012-05-25 18:22 ` redi at gcc dot gnu.org
  2012-05-25 18:24 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2012-05-25 18:22 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|blocker                     |normal

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-25 18:15:59 UTC ---
(Blocker means it blocks a GCC release, so changing priority.)

Is the progam_options library built with -std=c++11 ?


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

* [Bug c++/53490] Segmentation Fault when accessing std::set
  2012-05-25 18:13 [Bug c++/53490] New: Segmentation Fault when accessing std::set ja11sop at yahoo dot co.uk
  2012-05-25 18:22 ` [Bug c++/53490] " redi at gcc dot gnu.org
@ 2012-05-25 18:24 ` redi at gcc dot gnu.org
  2012-05-25 20:42 ` daniel.kruegler at googlemail dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2012-05-25 18:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-25 18:22:16 UTC ---
I only tried briefly but couldn't reproduce a crash with boost 1.47, will try
later with boost 1.49


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

* [Bug c++/53490] Segmentation Fault when accessing std::set
  2012-05-25 18:13 [Bug c++/53490] New: Segmentation Fault when accessing std::set ja11sop at yahoo dot co.uk
  2012-05-25 18:22 ` [Bug c++/53490] " redi at gcc dot gnu.org
  2012-05-25 18:24 ` redi at gcc dot gnu.org
@ 2012-05-25 20:42 ` daniel.kruegler at googlemail dot com
  2012-05-25 22:16 ` ja11sop at yahoo dot co.uk
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-05-25 20:42 UTC (permalink / raw)
  To: gcc-bugs

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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-05-25 20:29:48 UTC ---
At least for a mingw built of boost 1.49 and with gcc 4.8.0 20120520
(experimental) I get no runtime problem.


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

* [Bug c++/53490] Segmentation Fault when accessing std::set
  2012-05-25 18:13 [Bug c++/53490] New: Segmentation Fault when accessing std::set ja11sop at yahoo dot co.uk
                   ` (2 preceding siblings ...)
  2012-05-25 20:42 ` daniel.kruegler at googlemail dot com
@ 2012-05-25 22:16 ` ja11sop at yahoo dot co.uk
  2012-05-25 22:51 ` ja11sop at yahoo dot co.uk
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ja11sop at yahoo dot co.uk @ 2012-05-25 22:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jamie Allsop <ja11sop at yahoo dot co.uk> 2012-05-25 22:04:13 UTC ---
(In reply to comment #1)
> (Blocker means it blocks a GCC release, so changing priority.)
> 
> Is the progam_options library built with -std=c++11 ?

Thanks for fixing the priority. It was a vanilla bjam build of boost 1.49, so
no -std=c++11.


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

* [Bug c++/53490] Segmentation Fault when accessing std::set
  2012-05-25 18:13 [Bug c++/53490] New: Segmentation Fault when accessing std::set ja11sop at yahoo dot co.uk
                   ` (3 preceding siblings ...)
  2012-05-25 22:16 ` ja11sop at yahoo dot co.uk
@ 2012-05-25 22:51 ` ja11sop at yahoo dot co.uk
  2012-05-26  0:14 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: ja11sop at yahoo dot co.uk @ 2012-05-25 22:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jamie Allsop <ja11sop at yahoo dot co.uk> 2012-05-25 22:16:41 UTC ---
(In reply to comment #2)
> I only tried briefly but couldn't reproduce a crash with boost 1.47, will try
> later with boost 1.49

For clarity I should say I just tried with a vanilla build of 1.47 and get
essentially the same backtrace here.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7933427 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
(gdb) bt
#0  0x00007ffff7933427 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1  0x0000000000464233 in std::_Rb_tree_iterator<std::string>::operator--
(this=0x7fffffffdc60)
    at /usr/include/c++/4.7/bits/stl_tree.h:203
#2  0x0000000000462db0 in std::_Rb_tree<std::string, std::string,
std::_Identity<std::string>, std::less<std::string>,
std::allocator<std::string> >::_M_insert_unique<std::string const&>
(this=0x6a4540, __v=...)
    at /usr/include/c++/4.7/bits/stl_tree.h:1295
#3  0x0000000000461c2b in std::set<std::string, std::less<std::string>,
std::allocator<std::string> >::insert (
    this=0x6a4540, __x=...) at /usr/include/c++/4.7/bits/stl_set.h:415
#4  0x000000000047afb5 in boost::program_options::store (options=..., xm=...,
utf8=false)
    at libs/program_options/src/variables_map.cpp:98
#5  0x0000000000460480 in store_properties (argc=2, argv=0x7fffffffe0b0) at
program_options_test.cpp:31
#6  0x00000000004607db in main (argc=1, argv=0x7fffffffe1c8) at
program_options_test.cpp:64
(gdb)


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

* [Bug c++/53490] Segmentation Fault when accessing std::set
  2012-05-25 18:13 [Bug c++/53490] New: Segmentation Fault when accessing std::set ja11sop at yahoo dot co.uk
                   ` (4 preceding siblings ...)
  2012-05-25 22:51 ` ja11sop at yahoo dot co.uk
@ 2012-05-26  0:14 ` redi at gcc dot gnu.org
  2012-05-26 13:26 ` ja11sop at yahoo dot co.uk
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2012-05-26  0:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-26 00:02:13 UTC ---
(In reply to comment #4)
> It was a vanilla bjam build of boost 1.49, so
> no -std=c++11.

Then technically that's not supported, since there are no guarantees of
link-compatibility between -std=c++98 and -std=c++11 code (but I'm not aware of
any specific reasons it wouldn't work for a std::set)

(In reply to comment #5)
> For clarity I should say I just tried with a vanilla build of 1.47 and get
> essentially the same backtrace here.

I don't think the build of boost 1.47 I used earlier was non-vanilla in any
way, and I get no segfault on Fedora 16 using the system's
boost-static-1.47.0-6.fc16.x86_64.rpm with:

~/gcc/4.7/bin/g++ j.cc -std=c++11 -Wl,-Bstatic -lboost_program_options
-Wl,-Bdynamic

Is it significant that you link statically? Does it fail in the same way if you
link dynamically?


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

* [Bug c++/53490] Segmentation Fault when accessing std::set
  2012-05-25 18:13 [Bug c++/53490] New: Segmentation Fault when accessing std::set ja11sop at yahoo dot co.uk
                   ` (5 preceding siblings ...)
  2012-05-26  0:14 ` redi at gcc dot gnu.org
@ 2012-05-26 13:26 ` ja11sop at yahoo dot co.uk
  2012-05-28  9:32 ` ja11sop at yahoo dot co.uk
  2012-05-28  9:40 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: ja11sop at yahoo dot co.uk @ 2012-05-26 13:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jamie Allsop <ja11sop at yahoo dot co.uk> 2012-05-26 10:59:46 UTC ---
(In reply to comment #6)
> (In reply to comment #4)
> > It was a vanilla bjam build of boost 1.49, so
> > no -std=c++11.
> 
> Then technically that's not supported, since there are no guarantees of
> link-compatibility between -std=c++98 and -std=c++11 code (but I'm not aware of
> any specific reasons it wouldn't work for a std::set)
> 

So after sifting through the jam files to confirm there is no -std=c++11 set in
boost for gcc4.7 I modified my bjam invocations to add cxxflags="-std=c++11"
and now the test runs without the segfault. Verifying now on the full code
base. When the tests cycle and presumably pass I'll post back. It does look
however as if the mismatch in compile flags is the culprit here. Apologies for
not being thorough in checking that earlier.


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

* [Bug c++/53490] Segmentation Fault when accessing std::set
  2012-05-25 18:13 [Bug c++/53490] New: Segmentation Fault when accessing std::set ja11sop at yahoo dot co.uk
                   ` (6 preceding siblings ...)
  2012-05-26 13:26 ` ja11sop at yahoo dot co.uk
@ 2012-05-28  9:32 ` ja11sop at yahoo dot co.uk
  2012-05-28  9:40 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: ja11sop at yahoo dot co.uk @ 2012-05-28  9:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jamie Allsop <ja11sop at yahoo dot co.uk> 2012-05-28 09:09:30 UTC ---
(In reply to comment #7)
> (In reply to comment #6)
> > (In reply to comment #4)
> > > It was a vanilla bjam build of boost 1.49, so
> > > no -std=c++11.
> > 
> > Then technically that's not supported, since there are no guarantees of
> > link-compatibility between -std=c++98 and -std=c++11 code (but I'm not aware of
> > any specific reasons it wouldn't work for a std::set)
> > 
> 
> So after sifting through the jam files to confirm there is no -std=c++11 set in
> boost for gcc4.7 I modified my bjam invocations to add cxxflags="-std=c++11"
> and now the test runs without the segfault. Verifying now on the full code
> base. When the tests cycle and presumably pass I'll post back. It does look
> however as if the mismatch in compile flags is the culprit here. Apologies for
> not being thorough in checking that earlier.

All tests cycled and passed so I'd say this issue is understood now and user
error.


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

* [Bug c++/53490] Segmentation Fault when accessing std::set
  2012-05-25 18:13 [Bug c++/53490] New: Segmentation Fault when accessing std::set ja11sop at yahoo dot co.uk
                   ` (7 preceding siblings ...)
  2012-05-28  9:32 ` ja11sop at yahoo dot co.uk
@ 2012-05-28  9:40 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2012-05-28  9:40 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WORKSFORME

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-28 09:32:36 UTC ---
OK, thanks for confirming it.


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

end of thread, other threads:[~2012-05-28  9:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-25 18:13 [Bug c++/53490] New: Segmentation Fault when accessing std::set ja11sop at yahoo dot co.uk
2012-05-25 18:22 ` [Bug c++/53490] " redi at gcc dot gnu.org
2012-05-25 18:24 ` redi at gcc dot gnu.org
2012-05-25 20:42 ` daniel.kruegler at googlemail dot com
2012-05-25 22:16 ` ja11sop at yahoo dot co.uk
2012-05-25 22:51 ` ja11sop at yahoo dot co.uk
2012-05-26  0:14 ` redi at gcc dot gnu.org
2012-05-26 13:26 ` ja11sop at yahoo dot co.uk
2012-05-28  9:32 ` ja11sop at yahoo dot co.uk
2012-05-28  9:40 ` redi 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).