From ripley at stats.ox.ac.uk  Tue Aug  2 14:22:50 2005
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue, 2 Aug 2005 13:22:50 +0100 (BST)
Subject: [Rd] valgrind complains about regex.c (PR#8043)
In-Reply-To: <42EF5E1E.30105@stats.uwo.ca>
References: <20050801212527.C2689A75B@slim.kubism.ku.dk>
	<Pine.LNX.4.61.0508020704180.19394@gannet.stats>
	<42EF5E1E.30105@stats.uwo.ca>
Message-ID: <Pine.LNX.4.61.0508021315010.31827@gannet.stats>

Yes, optimization sometimes results in writes that are apparently 
harmless and go away if optimization is removed.

It could be the bug you found (and glibc-2.3.5 had fixed) but it isn't in 
exactly the right place.  But then, valgrind on my system does not have a 
problem with that one, optimized or not.

On Tue, 2 Aug 2005, Duncan Murdoch wrote:

> Prof Brian Ripley wrote:
>> Did you compile R without optimization?  Such reads are often the result of 
>> read-aheads produced by the optimizer in an attempt to keep pipelines full 
>> (and are harmless).
>
> There were both a read and a write.  I can see the read being harmless, but 
> is the write harmless?  I suspect this may be the bug I fixed on July 16, 
> since it had to do with character classes including ranges (like Charlie's 
> "[a-pr-z]").
>
> Charlie, have you tried a recent version of R-patched?
>
> Duncan Murdoch
>
>> 
>> On an un-optimized build of R I am unable to reproduce this.  (I also was 
>> unable to reproduce it on my optimized build of 2.1.1 using gcc 3.4.4, 
>> although I did get a report on other read-aheads.)
>> 
>> On Mon, 1 Aug 2005 charlie at stat.umn.edu wrote:
>> 
>> 
>>> I think I am using objects according to the man page.
>>> This seems to be a valid regular expression.  But whether
>>> I know what I'm doing or no, it still shouldn't be doing
>>> what valgrind seems to be saying it's doing.  (IMHO)
>> 
>> 
>> I think you need to take that up with compiler designers: it is common 
>> practice.
>> 
>> 
>>> ---------- start of script ----------
>>> Script started on Mon 01 Aug 2005 02:09:00 PM PDT
>>> linux$ printenv VALGRIND_OPTS
>>> --tool=3Dmemcheck
>>> linux$ cat bar.R
>>> 
>>> foo <- 1
>>> bar <- 2:3
>>> baz <- 4:6
>>> qux <- matrix(7:10, 2)
>>> 
>>> ls()
>>> rm(list =3D objects(pattern =3D "^[a-pr-z]"))
>>> ls()
>>> 
>>> linux$ R --version
>>> R 2.1.1 (2005-06-20).
>>> Copyright (C) 2005 R Development Core Team
>>> 
>>> R is free software and comes with ABSOLUTELY NO WARRANTY.
>>> You are welcome to redistribute it under the terms of the GNU
>>> General Public License.  For more information about these matters,
>>> see http://www.gnu.org/copyleft/gpl.html.
>>> linux$ gcc --version
>>> =1B[0mgcc (GCC) 3.3.5 20050117 (prerelease) (SUSE Linux)
>>> =1B[0mCopyright (C) 2003 Free Software Foundation, Inc.
>>> =1B[0mThis is free software; see the source for copying conditions.  There 
>>> =
>>> is NO
>>> =1B[0mwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR 
>>> PU=
>>> RPOSE.
>>> =1B[0m
>>> linux$ cat /etc/SuSE-release=20
>>> SuSE Linux 9.3 (i586)
>>> VERSION =3D 9.3
>>> linux$ R --vanilla --debugger=3Dvalgrind < bar.R >| bar.Rout
>>> =3D=3D22324=3D=3D Memcheck, a memory error detector for x86-linux.
>>> =3D=3D22324=3D=3D Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward 
>>> =
>>> et al.
>>> =3D=3D22324=3D=3D Using valgrind-2.2.0, a program supervision framework 
>>> for=
>>> x86-linux.
>>> =3D=3D22324=3D=3D Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward 
>>> =
>>> et al.
>>> =3D=3D22324=3D=3D For more details, rerun with: -v
>>> =3D=3D22324=3D=3D=20
>>> =3D=3D22324=3D=3D Invalid read of size 4
>>> =3D=3D22324=3D=3D    at 0x81255AD: parse_expression (regex.c:5045)
>>> =3D=3D22324=3D=3D    by 0x8125868: parse_branch (regex.c:4475)
>>> =3D=3D22324=3D=3D    by 0x8125913: parse_reg_exp (regex.c:4420)
>>> =3D=3D22324=3D=3D    by 0x81261B3: Rf_regcomp (regex.c:4384)
>>> =3D=3D22324=3D=3D  Address 0x1C1E23A8 is 0 bytes after a block of size 32 
>>> a=
>>> lloc'd
>>> =3D=3D22324=3D=3D    at 0x1B90650D: calloc (in 
>>> /usr/lib/valgrind/vgpreload_=
>>> memcheck.so)
>>> =3D=3D22324=3D=3D    by 0x81247B5: parse_expression (regex.c:5406)
>>> =3D=3D22324=3D=3D    by 0x8125868: parse_branch (regex.c:4475)
>>> =3D=3D22324=3D=3D    by 0x8125913: parse_reg_exp (regex.c:4420)
>>> =3D=3D22324=3D=3D=20
>>> =3D=3D22324=3D=3D Invalid write of size 4
>>> =3D=3D22324=3D=3D    at 0x81255B2: parse_expression (regex.c:5045)
>>> =3D=3D22324=3D=3D    by 0x8125868: parse_branch (regex.c:4475)
>>> =3D=3D22324=3D=3D    by 0x8125913: parse_reg_exp (regex.c:4420)
>>> =3D=3D22324=3D=3D    by 0x81261B3: Rf_regcomp (regex.c:4384)
>>> =3D=3D22324=3D=3D  Address 0x1C1E23A8 is 0 bytes after a block of size 32 
>>> a=
>>> lloc'd
>>> =3D=3D22324=3D=3D    at 0x1B90650D: calloc (in 
>>> /usr/lib/valgrind/vgpreload_=
>>> memcheck.so)
>>> =3D=3D22324=3D=3D    by 0x81247B5: parse_expression (regex.c:5406)
>>> =3D=3D22324=3D=3D    by 0x8125868: parse_branch (regex.c:4475)
>>> =3D=3D22324=3D=3D    by 0x8125913: parse_reg_exp (regex.c:4420)
>>> =3D=3D22324=3D=3D=20
>>> =3D=3D22324=3D=3D ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 39 
>>> f=
>>> rom 2)
>>> =3D=3D22324=3D=3D malloc/free: in use at exit: 12691882 bytes in 6426 
>>> block=
>>> s.
>>> =3D=3D22324=3D=3D malloc/free: 32534 allocs, 26108 frees, 33105500 bytes 
>>> al=
>>> located.
>>> =3D=3D22324=3D=3D For a detailed leak analysis,  rerun with: --leak-check=
>>> =3Dyes
>>> =3D=3D22324=3D=3D For counts of detected errors, rerun with: -v
>>> linux$ exit
>>> 
>>> Script done on Mon 01 Aug 2005 02:10:42 PM PDT
>>> ---------- end of script ----------
>>> --=20
>>> Charles Geyer
>>> Professor, School of Statistics
>>> University of Minnesota
>>> charlie at stat.umn.edu
>>> 
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>> 
>>> 
>> 
>> 
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] valgrind complains about regex.c (PR#8043)
Prof Brian Ripley