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-08 19:46 ` [Bug middle-end/32667] " rguenth at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 55+ 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] 55+ messages in thread

end of thread, other threads:[~2024-01-04 14:44 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-32667-4@http.gcc.gnu.org/bugzilla/>
2011-12-05 17:00 ` [Bug middle-end/32667] builtin operator= generates memcpy with overlapping memory regions lu_zero at gentoo dot org
2011-12-05 20:38 ` mans at mansr dot com
2011-12-06  8:46 ` [Bug middle-end/32667] block copy with exact overlap is expanded as memcpy rguenth at gcc dot gnu.org
2015-02-12  5:38 ` pinskia at gcc dot gnu.org
2015-02-12  9:00 ` rguenth at gcc dot gnu.org
2015-02-12  9:42 ` jakub at gcc dot gnu.org
2015-09-28 18:18 ` hugh at mimosa dot com
2021-06-09 18:50 ` public at timruffing dot de
2021-06-10  6:36 ` rguenther at suse dot de
2023-01-05  8:53 ` pinskia at gcc dot gnu.org
2023-01-05  9:19 ` nyh at math dot technion.ac.il
2023-01-06 18:48 ` lopresti at gmail dot com
2023-10-28 10:04 ` post+gcc at ralfj dot de
2023-11-21 15:57 ` bugdal at aerifal dot cx
2023-11-22  7:33 ` rguenther at suse dot de
2023-11-22 14:57 ` bugdal at aerifal dot cx
2023-11-22 15:06 ` jakub at gcc dot gnu.org
2023-11-22 19:07 ` bugdal at aerifal dot cx
2023-11-23  0:00 ` lopresti at gmail dot com
2023-11-23  7:44 ` post+gcc at ralfj dot de
2023-11-23  7:58 ` rguenth at gcc dot gnu.org
2023-11-23  8:03 ` fw at gcc dot gnu.org
2023-11-23  8:08 ` rguenther at suse dot de
2023-11-23  8:32 ` cvs-commit at gcc dot gnu.org
2023-11-23  8:39 ` jakub at gcc dot gnu.org
2023-11-23 13:54 ` bugdal at aerifal dot cx
2023-11-23 13:57 ` bugdal at aerifal dot cx
2023-11-23 14:41 ` public at timruffing dot de
2023-11-23 15:00 ` public at timruffing dot de
2023-11-23 15:01 ` sjames at gcc dot gnu.org
2023-11-23 15:29 ` post+gcc at ralfj dot de
2023-11-23 18:55 ` bugdal at aerifal dot cx
2023-11-23 19:04 ` post+gcc at ralfj dot de
2023-11-23 20:27 ` bugdal at aerifal dot cx
2023-11-24  8:19 ` public at timruffing dot de
2023-11-24  9:29 ` rguenth at gcc dot gnu.org
2023-11-24 10:09 ` jakub at gcc dot gnu.org
2023-11-24 19:08 ` post+gcc at ralfj dot de
2023-11-27 14:12 ` post+gcc at ralfj dot de
2023-11-27 23:32 ` joseph at codesourcery dot com
2023-11-28  7:17 ` post+gcc at ralfj dot de
2023-11-28  7:20 ` post+gcc at ralfj dot de
2023-11-28 10:58 ` rguenther at suse dot de
2023-11-28 11:03 ` rguenth at gcc dot gnu.org
2023-11-28 11:07 ` fw at gcc dot gnu.org
2024-01-04 12:52 ` rearnsha at gcc dot gnu.org
2024-01-04 13:22 ` bugdal at aerifal dot cx
2024-01-04 13:37 ` jakub at gcc dot gnu.org
2024-01-04 14:28 ` rearnsha at gcc dot gnu.org
2024-01-04 14:29 ` bugdal at aerifal dot cx
2024-01-04 14:41 ` rearnsha at gcc dot gnu.org
2024-01-04 14:44 ` bugdal at aerifal dot cx
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-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).