|
From: Konstantin S. <kon...@gm...> - 2009-05-06 07:42:09
|
On Tue, May 5, 2009 at 2:30 AM, Nicholas Nethercote <n.n...@gm...> wrote: > On Tue, May 5, 2009 at 5:03 AM, Konstantin Serebryany > <kon...@gm...> wrote: >> >> When copying structures of size 5, g++ (4.3.1) generates memcpy(dst, src, 5). >> It may happen that src==dst (see example below). >> src==dst is not allowed by the standard, but this code is not written >> by humans and the compiler knows it is correct >> (I asume that glibc will not explode with src==dst) >> >> Memcheck reports a warning. >> >> Even if this is a bug in gcc (is it?) we still need to workaround it >> in memcheck. >> Comments? > > These ones are always tricky, where the language spec doesn't match > what happens in practice. This case is particularly annoying because > we can't distinguish between a user-inserted memcpy() and a > GCC-generated one. It's arguably that GCC shouldn't generate such > code -- you say you assume glibc will not explode in this case, but > that is an assumption. > > So I don't know what to do. Maybe Julian will have some ideas. I would suggest two "workarounds": - add a flag that disables warnings on src=dst (off by default) or - generate a different kind of warning for src=dst. Right now memcheck reports warning of type Memcheck:Overlap for cases when the memory regions partially overlap and when they are equal. We can generate Memcheck:MemcpySrcEqualsDst for the latter case. This looks better but may break someone's suppression files. Which one do you prefer (if any)? --kcc > > Nick > |