Bug 198397

Summary: please support memcheck annotations for benign out of bound accesses
Product: [Developer tools] valgrind Reporter: Konstantin Serebryany <konstantin.s.serebryany>
Component: memcheckAssignee: Julian Seward <jseward>
Status: REPORTED ---    
Severity: normal    
Priority: NOR    
Version: 3.5 SVN   
Target Milestone: ---   
Platform: Unlisted Binaries   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: unittest
approximate patch

Description Konstantin Serebryany 2009-06-30 10:09:00 UTC
Summary: 
It would be nice to support memcheck annotations (client requests) that allow to mark intentional out of bound accesses and accesses to uninitialized memory as benign. 

Proposed syntax: 

Primary annotations: 
VALGRIND_IGNORE_READS_BEGIN()
VALGRIND_IGNORE_READS_END()
VALGRIND_IGNORE_WRITES_BEGIN()
VALGRIND_IGNORE_WRITES_END()

derived annotations: 
VALGRIND_UNCHECKED_MEM_READ(ptr)
VALGRIND_UNCHECKED_MEM_WRITE(lhs_ptr, rhs)

Detailed discussion: http://thread.gmane.org/gmane.comp.debugging.valgrind.devel/7375/focus=7377

an approximate patch and a unittest attached.
Comment 1 Konstantin Serebryany 2009-06-30 10:12:43 UTC
Created attachment 34933 [details]
unittest
Comment 2 Konstantin Serebryany 2009-06-30 10:13:25 UTC
Created attachment 34934 [details]
approximate patch
Comment 3 Julian Seward 2009-06-30 15:48:19 UTC
Re patch #3, that is going to add a minimum of two instructions
(cmpb $0, $ignore_reads; jcond ...) to all fast paths.  Ungood.

Here's an alternative suggestion: don't mess with the fast-case
handlers.  Instead, move the logic into MC_(record_address_error).
That means we only pay the cost of it for memory accesses which
do cause an error, instead of on all accesses.

In fact, see function MC_(in_ignored_range) called at top of
MC_(record_address_error).  A mechanism like this kind-of
already exists, in order to support the --ignore-ranges flag
for memcheck.

Although I should point out the resulting semantics are a bit different.