From patchwork Fri Oct 21 23:53:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 121095 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C5CD9B6FA5 for ; Sat, 22 Oct 2011 10:53:30 +1100 (EST) Received: (qmail 17027 invoked by alias); 21 Oct 2011 23:53:28 -0000 Received: (qmail 17016 invoked by uid 22791); 21 Oct 2011 23:53:28 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 21 Oct 2011 23:53:12 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9LNrBb4007391 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Oct 2011 19:53:11 -0400 Received: from localhost (ovpn-113-95.phx2.redhat.com [10.3.113.95]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p9LNrAIS023549 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 21 Oct 2011 19:53:11 -0400 Received: by localhost (Postfix, from userid 500) id 46B9A29C129; Sat, 22 Oct 2011 01:53:09 +0200 (CEST) From: Dodji Seketeli To: gcc-patches@gcc.gnu.org Cc: tromey@redhat.com, jason@redhat.com Subject: Re: [PATCH 2/2, libcpp] Fix lookup of macro maps References: <1319240276-26273-1-git-send-email-dodji@redhat.com> <1319240276-26273-3-git-send-email-dodji@redhat.com> X-URL: http://www.redhat.com Date: Sat, 22 Oct 2011 01:53:09 +0200 In-Reply-To: <1319240276-26273-3-git-send-email-dodji@redhat.com> (Dodji Seketeli's message of "Sat, 22 Oct 2011 01:37:56 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This is the right patch that I bootstrapped and tested. * line-map.c (linemap_macro_map_lookup): Make sure to always pick the map with the highest MAP_START_LOCATION. --- libcpp/line-map.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 352d697..ecfcfd0 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -588,14 +588,19 @@ linemap_macro_map_lookup (struct line_maps *set, source_location line) mn = 0; } - do + while (mx - mn > 1) { md = (mx + mn) / 2; if (MAP_START_LOCATION (LINEMAPS_MACRO_MAP_AT (set, md)) > line) mn = md; else mx = md; - } while (mx - mn > 1); + } + + /* There are cases where mx - mn = 1 and where the map we want is + mn. Let's not miss it. */ + if (MAP_START_LOCATION (LINEMAPS_MACRO_MAP_AT (set, mn)) <= line) + mx = mn; LINEMAPS_MACRO_CACHE (set) = mx; result = LINEMAPS_MACRO_MAP_AT (set, LINEMAPS_MACRO_CACHE (set));