From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26215 invoked by alias); 27 Feb 2015 11:43:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 26204 invoked by uid 89); 27 Feb 2015 11:43:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 27 Feb 2015 11:43:30 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by service87.mimecast.com; Fri, 27 Feb 2015 11:43:26 +0000 Received: from SHAWIN202 ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 27 Feb 2015 11:43:23 +0000 From: "Thomas Preud'homme" To: , "'Paolo Bonzini'" , "'Seongbae Park'" , "'Kenneth Zadeck'" Subject: [PATCH] Fix removing of df problem in df_finish_pass Date: Fri, 27 Feb 2015 12:07:00 -0000 Message-ID: <000601d05282$7fabdc60$7f039520$@arm.com> MIME-Version: 1.0 X-MC-Unique: 115022711432600601 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2015-02/txt/msg01695.txt.bz2 Hi, In df_finish_pass, optional problems are removed manually making non null entries in df->problems_in_order non contiguous. This may lead to null poin= ter dereference when accessing all problems from df->problems_in_order[0] to df->problems_in_order[df->num_problems_defined - 1] and miss some other problems. Such a scenario was actually encountered when working on a patch. This patch use the existing function df_remove_problem to do the deletion, which require iterating on problems via the df->problems_by_index[] array since each call mess up with df->num_problems_defined and order of problems in df->problems_in_order[]. ChangeLog entry is as follows: 2015-02-12 Thomas Preud'homme * df-core.c (df_finish_pass): Iterate over df->problems_by_index[] = and use df_remove_problem rather than manually removing problems, living holes in df->problems_in_order[]. diff --git a/gcc/df-core.c b/gcc/df-core.c index 82f1364..67040a1 100644 --- a/gcc/df-core.c +++ b/gcc/df-core.c @@ -642,7 +642,6 @@ void df_finish_pass (bool verify ATTRIBUTE_UNUSED) { int i; - int removed =3D 0; =20 #ifdef ENABLE_DF_CHECKING int saved_flags; @@ -658,21 +657,15 @@ df_finish_pass (bool verify ATTRIBUTE_UNUSED) saved_flags =3D df->changeable_flags; #endif =20 - for (i =3D 0; i < df->num_problems_defined; i++) + /* We iterate over problems by index as each problem removed will + lead to problems_in_order to be reordered. */ + for (i =3D 0; i < DF_LAST_PROBLEM_PLUS1; i++) { - struct dataflow *dflow =3D df->problems_in_order[i]; - struct df_problem *problem =3D dflow->problem; + struct dataflow *dflow =3D df->problems_by_index[i]; =20 - if (dflow->optional_p) - { - gcc_assert (problem->remove_problem_fun); - (problem->remove_problem_fun) (); - df->problems_in_order[i] =3D NULL; - df->problems_by_index[problem->id] =3D NULL; - removed++; - } + if (dflow && dflow->optional_p) + df_remove_problem (dflow); } - df->num_problems_defined -=3D removed; =20 /* Clear all of the flags. */ df->changeable_flags =3D 0; Testsuite was run with a bootstrapped x86_64 native compiler and an arm-none-eabi GCC cross-compiler targetting Cortex-M3 without any regression. Although the problem is real, it doesn't seem that GCC hits it now (I stumbled upon it while working on a patch). Therefore I'm not sure if this should go in stage4 or not. Please advise me on this. Ok for trunk/stage1? Best regards, Thomas