public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51231] New: g++ remove placement new with -O1
@ 2011-11-19 22:04 dushistov at mail dot ru
  2011-11-19 22:07 ` [Bug c++/51231] " dushistov at mail dot ru
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: dushistov at mail dot ru @ 2011-11-19 22:04 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51231
           Summary: g++ remove placement new with -O1
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: dushistov@mail.ru


If code bellow compile with -O1 it prints '0', while with '-O0' it prints
deadbeaf.

The problem in   allocator.construct (allocator.address (at), value);
In boost_1_46_1/boost/interprocess/allocators/allocator.hpp it looks like:
void construct(const pointer &ptr, const_reference v)
   {  new((void*)detail::get_pointer(ptr)) value_type(v);  }

if rewrite it for example in such way:
 void construct(const pointer &ptr, const_reference v)
   {
        static volatile value_type *myp;
        myp = detail::get_pointer(ptr);
        ::new((void *)myp) value_type(v);
   }

the code print expected value: deadbeaf.

#include <iostream>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/managed_shared_memory.hpp>

namespace interp = boost::interprocess;

struct interp_memory_chunk
{
  interp::managed_shared_memory  chunk;

  interp_memory_chunk ()
  {
    interp::shared_memory_object::remove ("GCC_interprocess_test");
    chunk = interp::managed_shared_memory (interp::create_only,
"GCC_interprocess_test", 0x10000);
  }

  ~interp_memory_chunk ()
  {
    interp::shared_memory_object::remove ("GCC_interprocess_test");
  }
};

typedef  interp::allocator <int,
interp::managed_shared_memory::segment_manager>  allocator_type;

inline  void
create (allocator_type& allocator, allocator_type::value_type& at, int value)
{
  allocator.construct (allocator.address (at), value);
}

int
main ()
{
  interp_memory_chunk      memory;
  allocator_type           allocator (memory.chunk.get_segment_manager ());
  allocator_type::pointer  data = allocator.allocate (1);

  create (allocator, *data, 0xdeadbeef);
  std::cout << std::hex << *data << "\n";
}


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

end of thread, other threads:[~2012-02-07 11:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-19 22:04 [Bug c++/51231] New: g++ remove placement new with -O1 dushistov at mail dot ru
2011-11-19 22:07 ` [Bug c++/51231] " dushistov at mail dot ru
2011-11-19 22:59 ` dushistov at mail dot ru
2011-11-19 23:17 ` dushistov at mail dot ru
2011-11-21 14:45 ` dushistov at mail dot ru
2011-12-15  0:53 ` [Bug regression/51231] " pinskia at gcc dot gnu.org
2012-02-02  8:22 ` [Bug middle-end/51231] [4.5/4.6/4.7 Regression] " pinskia at gcc dot gnu.org
2012-02-07 11: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).