From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14673 invoked by alias); 20 Jun 2009 15:01:34 -0000 Received: (qmail 14522 invoked by uid 22791); 20 Jun 2009 15:01:33 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from qw-out-1920.google.com (HELO qw-out-1920.google.com) (74.125.92.145) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 20 Jun 2009 15:01:28 +0000 Received: by qw-out-1920.google.com with SMTP id 4so1189252qwk.14 for ; Sat, 20 Jun 2009 08:01:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.44.204 with SMTP id b12mr3348119vcf.101.1245510085691; Sat, 20 Jun 2009 08:01:25 -0700 (PDT) In-Reply-To: <4A3CF81C.7050406@redhat.com> References: <4A3CF81C.7050406@redhat.com> Date: Sat, 20 Jun 2009 15:01:00 -0000 Message-ID: <84fc9c000906200801v28f814cj3fa5327c5f3df35e@mail.gmail.com> Subject: Re: (known?) Issue with bitmap iterators From: Richard Guenther To: Jeff Law Cc: GCC Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2009-06/txt/msg00483.txt.bz2 On Sat, Jun 20, 2009 at 4:54 PM, Jeff Law wrote: > > Imagine a loop like this > > EXECUTE_IF_SET_IN_BITMAP (something, 0, i, bi) > =A0{ > =A0 bitmap_clear_bit (something, i) > =A0 [ ... whatever code we want to process i, ... ] > =A0} > > This code is unsafe. > > If bit I happens to be the only bit set in the current bitmap word, then > bitmap_clear_bit will free the current element and return it to the eleme= nt > free list where it can be recycled. > > So assume the bitmap element gets recycled for some other bitmap... =A0We= then > come around to the top of the loop where EXECUTE_IF_SET_IN_BITMAP will ca= ll > bmp_iter_set which can reference the recycled element when it tries to > advance to the next element via bi->elt1 =3D bi->elt1->next. =A0So we sta= rt > iterating on elements of a completely different bitmap. =A0You can assume= this > is not good. > > Our documentation clearly states that I is to remain unchanged, but ISTM > that the bitmap we're iterating over needs to remain unchanged as well. > Is this a known issue, or am I just the lucky bastard who tripped over it > and now gets to audit all the EXECUTE_IF_SET_IN_BITMAP loops? It is known (but maybe not appropriately documented) that deleting bits in the bitmap you iterate over is not safe. If it would be me I would see if I could make it safe though. Richard. > Jeff >