From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 99938 invoked by alias); 25 Apr 2015 21:13:50 -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 99921 invoked by uid 89); 25 Apr 2015 21:13:50 -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,RCVD_IN_DNSWL_NONE,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: smtp23.services.sfr.fr Received: from smtp23.services.sfr.fr (HELO smtp23.services.sfr.fr) (93.17.128.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Sat, 25 Apr 2015 21:13:48 +0000 Received: from filter.sfr.fr (localhost [86.72.15.103]) by msfrf2321.sfr.fr (SMTP Server) with ESMTP id 29FC47000219; Sat, 25 Apr 2015 23:13:45 +0200 (CEST) Authentication-Results: sfrmc.priv.atos.fr; dkim=none (no signature); dkim-adsp=none (no policy) header.from=mikael.morin@sfr.fr Received: from tolstoi.localhost (103.15.72.86.rev.sfr.net [86.72.15.103]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by msfrf2321.sfr.fr (SMTP Server) with ESMTP id CC43470001C1; Sat, 25 Apr 2015 23:13:44 +0200 (CEST) X-SFR-UUID: 20150425211344836.CC43470001C1@msfrf2321.sfr.fr Message-ID: <553C037E.3090006@sfr.fr> Date: Sat, 25 Apr 2015 21:13:00 -0000 From: Mikael Morin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Andre Vehreschild , GCC-Patches-ML , GCC-Fortran-ML Subject: Re: [Patch, Fortran] Prevent segfault with dump-*-original for implicit class expressions. References: <20150313113339.32440f8c@vepi2> In-Reply-To: <20150313113339.32440f8c@vepi2> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2015-04/txt/msg01553.txt.bz2 Hello, Le 13/03/2015 11:33, Andre Vehreschild a écrit : > Hi all, > > this is another patch preventing a segfault. This time the segfault occurred, > when -fdump-(fortran|tree)-original was given with the program having an > implicit class set. The issue is that the _data component is assumed to be > present in a BT_CLASS w/o checking and trying to access the unlimited > polymorphic flag there. The patch fixes this by redirecting the access to the > flag to the correct position whether the _data component is present or not. > > Building a testcase for this is difficult for me. May be I am just blocked in > the head there. The issue occurred when trying to dump the > (fortran|tree)-original of the testcase gfortran.dg/implicit_class_1.f90. So > one could argue to add the flag to that testcase, but does it pay in contrast > to the additional effort each time the testsuite is executed? I have added the > test now, not being happy with it, but having no clue how to do it better. > > Bootstraps and regtests ok on x86_64-linux-gnu/F20. > > Ok, for trunk? > Comments below: b/gcc/fortran/symbol.c > index 32eea21..3379f47 100644 > --- a/gcc/fortran/symbol.c > +++ b/gcc/fortran/symbol.c (skipped) The beginning looks good. I suggest using 'ts->u.derived->attr.is_class' instead of 'strcmp (ts->u.derived.components->name, "_data") == 0'. No strong opinion, your choice. > @@ -4576,13 +4579,14 @@ gfc_type_compatible (gfc_typespec *ts1, gfc_typespec *ts2) > if (is_derived1 && is_derived2) > return gfc_compare_derived_types (ts1->u.derived, ts2->u.derived); > > - if (is_derived1 && is_class2) > + if (is_derived1 && is_class2 && ts2->u.derived->components) > return gfc_compare_derived_types (ts1->u.derived, > ts2->u.derived->components->ts.u.derived); > - if (is_class1 && is_derived2) > + if (is_class1 && is_derived2 && ts1->u.derived->components) > return gfc_type_is_extension_of (ts1->u.derived->components->ts.u.derived, > ts2->u.derived); > - else if (is_class1 && is_class2) > + else if (is_class1 && is_class2 && ts1->u.derived->components > + && ts2->u.derived->components) > return gfc_type_is_extension_of (ts1->u.derived->components->ts.u.derived, > ts2->u.derived->components->ts.u.derived); > else The above change don't seem right. In the case where the class container is missing, you want to use "ts->u.derived" instead of "ts->u.derived->components->ts.u.derived", not skip the procedure call entirely. > diff --git a/gcc/testsuite/gfortran.dg/implicit_class_1.f90 b/gcc/testsuite/gfortran.dg/implicit_class_1.f90 > index 329f57a..fff1f2b 100644 > --- a/gcc/testsuite/gfortran.dg/implicit_class_1.f90 > +++ b/gcc/testsuite/gfortran.dg/implicit_class_1.f90 > @@ -4,6 +4,10 @@ > ! > ! Contributed by Reinhold Bader > > +! Add dump-tree-original to check, if the patch preventing a gfortran > +! segfault is working correctly. > +! { dg-options "-fdump-tree-original" } > + -fdump-tree-original doesn't trigger any bug here. So use -fdump-fortran-original (I'm not sure the testsuite will like it). Mikael