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
* [Bug c++/51231] g++ remove placement new with -O1
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 ` dushistov at mail dot ru
2011-11-19 22:59 ` dushistov at mail dot ru
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: dushistov at mail dot ru @ 2011-11-19 22:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51231
--- Comment #1 from Evgeniy Dushistov <dushistov at mail dot ru> 2011-11-19 21:49:33 UTC ---
The code works as expected for 4.4.5,
and show buggy behaviour with 4.5.3 and 4.6.2.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/51231] g++ remove placement new with -O1
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
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: dushistov at mail dot ru @ 2011-11-19 22:59 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51231
--- Comment #2 from Evgeniy Dushistov <dushistov at mail dot ru> 2011-11-19 22:03:49 UTC ---
Created attachment 25862
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25862
the preprocessed test case
generate from source with command:
g++ -ggdb -c -save-temps -O1 -Wall -Wextra boost_interp_alloc.cpp,
you still need -lboost_thread to create executable.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/51231] g++ remove placement new with -O1
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
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: dushistov at mail dot ru @ 2011-11-19 23:17 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51231
--- Comment #3 from Evgeniy Dushistov <dushistov at mail dot ru> 2011-11-19 22:07:40 UTC ---
To build test case you need use command:
g++ -ggdb -O1 -Wall -Wextra boost_interp_alloc.cpp -lboost_thread
I use boost 1.46.1.
Or you can use preprocessed attachment to look at generated assembler.
Tested on x86_64.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/51231] g++ remove placement new with -O1
2011-11-19 22:04 [Bug c++/51231] New: g++ remove placement new with -O1 dushistov at mail dot ru
` (2 preceding siblings ...)
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
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: dushistov at mail dot ru @ 2011-11-21 14:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51231
Evgeniy Dushistov <dushistov at mail dot ru> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |4.4.5
Known to fail| |4.5.3, 4.6.2
Severity|normal |major
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug regression/51231] g++ remove placement new with -O1
2011-11-19 22:04 [Bug c++/51231] New: g++ remove placement new with -O1 dushistov at mail dot ru
` (3 preceding siblings ...)
2011-11-21 14:45 ` dushistov at mail dot ru
@ 2011-12-15 0:53 ` 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
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-12-15 0:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51231
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|major |normal
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/51231] [4.5/4.6/4.7 Regression] g++ remove placement new with -O1
2011-11-19 22:04 [Bug c++/51231] New: g++ remove placement new with -O1 dushistov at mail dot ru
` (4 preceding siblings ...)
2011-12-15 0:53 ` [Bug regression/51231] " pinskia at gcc dot gnu.org
@ 2012-02-02 8:22 ` pinskia at gcc dot gnu.org
2012-02-07 11:46 ` rguenth at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-02-02 8:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51231
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Component|regression |middle-end
Target Milestone|--- |4.5.4
Summary|g++ remove placement new |[4.5/4.6/4.7 Regression]
|with -O1 |g++ remove placement new
| |with -O1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/51231] [4.5/4.6/4.7 Regression] g++ remove placement new with -O1
2011-11-19 22:04 [Bug c++/51231] New: g++ remove placement new with -O1 dushistov at mail dot ru
` (5 preceding siblings ...)
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
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-02-07 11:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51231
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-02-07 11:45:31 UTC ---
Confirmed. The store of 0xdeadbeef is gone:
void create(allocator_type&, boost::interprocess::allocator<int,
boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,
boost::interprocess::iset_index> >::value_type&, int) (struct allocator_type &
allocator, value_type & at, int value)
{
value_type * myp;
const ptrdiff_t D.99202;
sizetype D.99201;
struct pointer D.83867;
<bb 2>:
# USE = nonlocal { D.83867 }
# CLB = nonlocal { D.83867 }
D.83867 = boost::interprocess::allocator<int,
boost::interprocess::segment_manager<char,
boost::interprocess::rbtree_best_fit<boost::interprocess::mutex_family>,
boost::interprocess::iset_index> >::address (allocator_1(D), at_2(D)); [return
slot optimization]
D.99202_7 = D.83867.internal.m_offset;
if (D.99202_7 != 1)
goto <bb 3>;
else
goto <bb 4>;
<bb 3>:
D.99201_8 = (sizetype) D.99202_7;
# PT = { D.83867 }
myp_9 = &D.83867 + D.99201_8;
<bb 4>:
# PT = null { D.83867 }
# myp_10 = PHI <0B(2), myp_9(3)>
if (myp_10 != 0B)
goto <bb 5>;
else
goto <bb 6>;
<bb 5>:
value_11 = value_14(D);
*myp_10 = value_11;
<bb 6>:
D.83867 ={v} {CLOBBER};
return;
}
in ealias. Note that Boost invokes undefined behavior here as it
computes &D.83867 + D.83867.internal.m_offset which supposedly
points to an object that is not D.83867 obviously, as that is
automatic in function create() and the store would be dead anyway.
^ 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).