public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32667] New: builtin operator= generates memcpy with overlapping memory regions
@ 2007-07-07 17:55 Raimund dot Merkert at baesystems dot com
2007-07-07 18:19 ` [Bug c++/32667] " pcarlini at suse dot de
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Raimund dot Merkert at baesystems dot com @ 2007-07-07 17:55 UTC (permalink / raw)
To: gcc-bugs
This code generates a warning when run with valgrind:
#include <vector>
using namespace ::std;
struct X {
double values[10];
};
int main()
{
vector<X> x;
x.push_back(X());
for (vector<X>::iterator i=x.begin();i!=x.end();++i) {
*i = *(x.end()-1);
}
return 0;
}
g++ test.cpp -o foo -O3
Valgrind error:
valgrind --tool=memcheck foo
==24513== Memcheck, a memory error detector for x86-linux.
==24513== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward et al.
==24513== Using valgrind-2.2.0, a program supervision framework for x86-linux.
==24513== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward et al.
==24513== For more details, rerun with: -v
==24513==
==24513== Source and destination overlap in memcpy(0x1BB68028, 0x1BB68028, 80)
==24513== at 0x1B9057E5: memcpy (in /usr/lib/valgrind/vgpreload_memcheck.so)
==24513== by 0x8048696: main (in /home/ray/tmp/foo)
==24513==
==24513== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 17 from 1)
==24513== malloc/free: in use at exit: 0 bytes in 0 blocks.
==24513== malloc/free: 1 allocs, 1 frees, 80 bytes allocated.
==24513== For a detailed leak analysis, rerun with: --leak-check=yes
==24513== For counts of detected errors, rerun with: -v
On my machine "man memcpy" says "...The memory areas may not overlap. Use
memmove(3) if the memory areas do overlap. ..."
--
Summary: builtin operator= generates memcpy with overlapping
memory regions
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Raimund dot Merkert at baesystems dot com
GCC host triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32667
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/32667] builtin operator= generates memcpy with overlapping memory regions
2007-07-07 17:55 [Bug c++/32667] New: builtin operator= generates memcpy with overlapping memory regions Raimund dot Merkert at baesystems dot com
@ 2007-07-07 18:19 ` pcarlini at suse dot de
2007-07-07 22:36 ` Raimund dot Merkert at baesystems dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pcarlini at suse dot de @ 2007-07-07 18:19 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pcarlini at suse dot de 2007-07-07 18:19 -------
Interesting: mainline is not affected by the problem. I would guess thanks to
fixing libstdc++/29286 ???
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32667
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/32667] builtin operator= generates memcpy with overlapping memory regions
2007-07-07 17:55 [Bug c++/32667] New: builtin operator= generates memcpy with overlapping memory regions Raimund dot Merkert at baesystems dot com
2007-07-07 18:19 ` [Bug c++/32667] " pcarlini at suse dot de
@ 2007-07-07 22:36 ` Raimund dot Merkert at baesystems dot com
2007-07-08 19:46 ` [Bug middle-end/32667] " rguenth at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Raimund dot Merkert at baesystems dot com @ 2007-07-07 22:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from Raimund dot Merkert at baesystems dot com 2007-07-07 22:36 -------
This may be an old bug and may have crept in between 3.3.3 and 3.4.0 (latter
has it, former doesn't)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32667
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/32667] builtin operator= generates memcpy with overlapping memory regions
2007-07-07 17:55 [Bug c++/32667] New: builtin operator= generates memcpy with overlapping memory regions Raimund dot Merkert at baesystems dot com
2007-07-07 18:19 ` [Bug c++/32667] " pcarlini at suse dot de
2007-07-07 22:36 ` Raimund dot Merkert at baesystems dot com
@ 2007-07-08 19:46 ` rguenth at gcc dot gnu dot org
2007-07-08 20:53 ` pcarlini at suse dot de
2009-05-06 16:37 ` ppluzhnikov at google dot com
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-07-08 19:46 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2007-07-08 19:46 -------
No, this doesn't have anything to do with aliasing. 4.3 simply inlines the
memcpys. This is probably a middle-end issue with expanding structure
assignments. 2.95 and 3.3 also expanded the calls inline. 3.4 does not,
likewise 4.0, 4.1 and 4.2.
Note that this is likely not a problem in practice as memcpy (p, p, sizeof
(*p))
is difficult to implement in a way that would make it not work. So,
downgrading
severity.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu dot
| |org
Severity|major |normal
Status|UNCONFIRMED |NEW
Component|c++ |middle-end
Ever Confirmed|0 |1
Keywords| |wrong-code
Last reconfirmed|0000-00-00 00:00:00 |2007-07-08 19:46:19
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32667
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/32667] builtin operator= generates memcpy with overlapping memory regions
2007-07-07 17:55 [Bug c++/32667] New: builtin operator= generates memcpy with overlapping memory regions Raimund dot Merkert at baesystems dot com
` (2 preceding siblings ...)
2007-07-08 19:46 ` [Bug middle-end/32667] " rguenth at gcc dot gnu dot org
@ 2007-07-08 20:53 ` pcarlini at suse dot de
2009-05-06 16:37 ` ppluzhnikov at google dot com
4 siblings, 0 replies; 6+ messages in thread
From: pcarlini at suse dot de @ 2007-07-08 20:53 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from pcarlini at suse dot de 2007-07-08 20:53 -------
Thanks for the clarification, Richard.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32667
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/32667] builtin operator= generates memcpy with overlapping memory regions
2007-07-07 17:55 [Bug c++/32667] New: builtin operator= generates memcpy with overlapping memory regions Raimund dot Merkert at baesystems dot com
` (3 preceding siblings ...)
2007-07-08 20:53 ` pcarlini at suse dot de
@ 2009-05-06 16:37 ` ppluzhnikov at google dot com
4 siblings, 0 replies; 6+ messages in thread
From: ppluzhnikov at google dot com @ 2009-05-06 16:37 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from ppluzhnikov at google dot com 2009-05-06 16:36 -------
(In reply to comment #3)
> Note that this is likely not a problem in practice as
> memcpy (p, p, sizeof (*p)) is difficult to implement
> in a way that would make it not work.
>From Julian Seward:
JS> AIUI, POSIX says the src==dst case is not allowed (along with all other
JS> overlapping cases) because (eg) on PowerPC, it is possible to make a high
JS> performance memcpy that preallocates the destination area in D1 using
JS> dcbz instructions, which create the line in D1 and fill it full of
JS> zeroes. This avoids dragging the destination line up the memory
JS> hierarchy only to completely overwrite it with stuff from the source.
JS>
JS> Result is however that if the src and dst overlap, in any way, including
JS> completely, then this causes zeroes to be written into the src area (!)
JS> which is certainly not what you want.
This bug is likely fixed by:
http://gcc.gnu.org/ml/gcc-patches/2009-04/msg00932.html
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32667
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-05-06 16:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-07 17:55 [Bug c++/32667] New: builtin operator= generates memcpy with overlapping memory regions Raimund dot Merkert at baesystems dot com
2007-07-07 18:19 ` [Bug c++/32667] " pcarlini at suse dot de
2007-07-07 22:36 ` Raimund dot Merkert at baesystems dot com
2007-07-08 19:46 ` [Bug middle-end/32667] " rguenth at gcc dot gnu dot org
2007-07-08 20:53 ` pcarlini at suse dot de
2009-05-06 16:37 ` ppluzhnikov at google dot com
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).