Bug 301922 - gcc -O2 problem with SSE optimization?
Summary: gcc -O2 problem with SSE optimization?
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (show other bugs)
Version: 3.7 SVN
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-14 17:44 UTC by kapare
Modified: 2012-08-17 07:43 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Source file to reproduce the bug (428 bytes, text/x-c++src)
2012-06-14 17:44 UTC, kapare
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kapare 2012-06-14 17:44:03 UTC
Created attachment 71835 [details]
Source file to reproduce the bug

Hi,

Here the problem that I have with valgrind-3.6.1-Debian (Ubuntu 11.10), valgrind-3.7.0 (Ubuntu 12.04) and with the current SVN version (valgrind-3.8.0.SVN):

gcc -o test MallocProblemO2.cxx
valgrind --leak-check=full ./test

No problem

If I add the -O2 flag it result in a Invalid read of 4 bytes:

gcc -O2 -o test MallocProblemO2.cxx
valgrind --leak-check=full ./test

==21719== Memcheck, a memory error detector
==21719== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==21719== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
==21719== Command: ./test
==21719== 
==21719== Invalid read of size 4
==21719==    at 0x4004F0: main (in /home/kapare/Documents/test)
==21719==  Address 0x51d0044 is 4 bytes inside a block of size 6 alloc'd
==21719==    at 0x4C279F2: calloc (vg_replace_malloc.c:467)
==21719==    by 0x4004DF: main (in /home/kapare/Documents/test)
==21719== 
EXPECT STRLENGTH OF 4: 4
EXPECT STR "0123": 0123
==21719== 
==21719== HEAP SUMMARY:
==21719==     in use at exit: 0 bytes in 0 blocks
==21719==   total heap usage: 1 allocs, 1 frees, 6 bytes allocated
==21719== 
==21719== All heap blocks were freed -- no leaks are possible
==21719== 
==21719== For counts of detected and suppressed errors, rerun with: -v
==21719== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)


This problem seem to be the same as this old one?:
https://bugzilla.redhat.com/show_bug.cgi?id=518247

see attachment to reproduce the problem

Regards,

Kevyn-Alexandre Pare
Comment 1 kapare 2012-06-14 17:51:41 UTC
Replacing the bufferLength, in the source code previously attached, by 8 will solve the warning
Comment 2 kapare 2012-06-14 20:00:16 UTC
tested with debian unstable pacakage gcc 7.0, same result.
Comment 3 kapare 2012-06-14 20:03:41 UTC
Dan Kegel :Could this be the same problem as describe in Bug 264936 ?
Comment 4 kapare 2012-06-14 23:30:39 UTC
Test with or without --partial-loads-ok=yes

rm test;gcc -O2 -o test MallocProblemO2.cxx;valgrind --leak-check=full ./test
==27633== Memcheck, a memory error detector
==27633== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==27633== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
==27633== Command: ./test
==27633== 
==27633== Invalid read of size 4
==27633==    at 0x4004F0: main (in /home/kapare/Documents/test)
==27633==  Address 0x51d0044 is 4 bytes inside a block of size 6 alloc'd
==27633==    at 0x4C279F2: calloc (vg_replace_malloc.c:467)
==27633==    by 0x4004DF: main (in /home/kapare/Documents/test)
==27633== 
EXPECT STRLENGTH OF 4: 4
EXPECT STR "0123": 0123
==27633== 
==27633== HEAP SUMMARY:
==27633==     in use at exit: 0 bytes in 0 blocks
==27633==   total heap usage: 1 allocs, 1 frees, 6 bytes allocated
==27633== 
==27633== All heap blocks were freed -- no leaks are possible
==27633== 
==27633== For counts of detected and suppressed errors, rerun with: -v
==27633== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)

kapare@kapare:~/Documents$ rm test;gcc -O2 -o test MallocProblemO2.cxx;valgrind --partial-loads-ok=yes --leak-check=full ./test
==27663== Memcheck, a memory error detector
==27663== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==27663== Using Valgrind-3.6.1-Debian and LibVEX; rerun with -h for copyright info
==27663== Command: ./test
==27663== 
==27663== Invalid read of size 4
==27663==    at 0x4004F0: main (in /home/kapare/Documents/test)
==27663==  Address 0x51d0044 is 4 bytes inside a block of size 6 alloc'd
==27663==    at 0x4C279F2: calloc (vg_replace_malloc.c:467)
==27663==    by 0x4004DF: main (in /home/kapare/Documents/test)
==27663== 
EXPECT STRLENGTH OF 4: 4
EXPECT STR "0123": 0123
==27663== 
==27663== HEAP SUMMARY:
==27663==     in use at exit: 0 bytes in 0 blocks
==27663==   total heap usage: 1 allocs, 1 frees, 6 bytes allocated
==27663== 
==27663== All heap blocks were freed -- no leaks are possible
==27663== 
==27663== For counts of detected and suppressed errors, rerun with: -v
==27663== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)

WITH LAST SVN VERSION

rm test;gcc -O2 -o test MallocProblemO2.cxx;/home/kapare/VALGRIND/bin/valgrind --partial-loads-ok=yes --leak-check=full ./test
==27739== Memcheck, a memory error detector
==27739== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==27739== Using Valgrind-3.8.0.SVN and LibVEX; rerun with -h for copyright info
==27739== Command: ./test
==27739== 
==27739== Invalid read of size 4
==27739==    at 0x4004F0: main (in /home/kapare/Documents/test)
==27739==  Address 0x51d2044 is 4 bytes inside a block of size 6 alloc'd
==27739==    at 0x4C28864: calloc (vg_replace_malloc.c:590)
==27739==    by 0x4004DF: main (in /home/kapare/Documents/test)
==27739== 
EXPECT STRLENGTH OF 4: 4
EXPECT STR "0123": 0123
==27739== 
==27739== HEAP SUMMARY:
==27739==     in use at exit: 0 bytes in 0 blocks
==27739==   total heap usage: 1 allocs, 1 frees, 6 bytes allocated
==27739== 
==27739== All heap blocks were freed -- no leaks are possible
==27739== 
==27739== For counts of detected and suppressed errors, rerun with: -v
==27739== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)
Comment 5 kapare 2012-06-14 23:36:28 UTC
The last diff from line error from 3.6 to 3.8:

3.7  at 0x4C279F2: calloc (vg_replace_malloc.c:467)
3.8  at 0x4C28864: calloc  (vg_replace_malloc.c:590)
Comment 6 kapare 2012-06-14 23:50:00 UTC
The previous test was done with 
gcc --version
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1

I just tested it with gcc 7.0 on my debian machine with or without the --partial-loads-ok=yes there is no error!!!! So this seem a gcc problem will try on ubnutu 12.04 tomorrow :::

rm test;gcc --version;gcc -O2 -o test MallocProblemO2.cxx;valgrind --leak-check=full ./test
gcc (Debian 4.7.0-12) 4.7.0
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

==32142== Memcheck, a memory error detector
==32142== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==32142== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==32142== Command: ./test
==32142== 
EXPECT STRLENGTH OF 4: 4
EXPECT STR "0123": 0123
==32142== 
==32142== HEAP SUMMARY:
==32142==     in use at exit: 0 bytes in 0 blocks
==32142==   total heap usage: 1 allocs, 1 frees, 6 bytes allocated
==32142== 
==32142== All heap blocks were freed -- no leaks are possible
==32142== 
==32142== For counts of detected and suppressed errors, rerun with: -v
==32142== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
Comment 7 Julian Seward 2012-08-17 07:43:23 UTC
I can reproduce this with gcc 4.6.2 but not with gcc 4.7.1.