From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11181 invoked by alias); 26 Dec 2012 17:56:52 -0000 Received: (qmail 11086 invoked by uid 48); 26 Dec 2012 17:56:32 -0000 From: "pault at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/54992] [4.8 Regression] [OOP] Wrong offset in the array offset calculation when using nonclass%class(index)%nonclass Date: Wed, 26 Dec 2012 17:56:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: pault at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P4 X-Bugzilla-Assigned-To: pault at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.8.0 X-Bugzilla-Changed-Fields: AssignedTo Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-12/txt/msg02338.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54992 Paul Thomas changed: What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|unassigned at gcc dot |pault at gcc dot gnu.org |gnu.org | --- Comment #4 from Paul Thomas 2012-12-26 17:56:31 UTC --- This is another result of the underlying bug unearthed in PR54990. Index: gcc/fortran/trans-array.c =================================================================== *** gcc/fortran/trans-array.c (revision 194721) --- gcc/fortran/trans-array.c (working copy) *************** static tree *** 3099,3112 **** build_array_ref (tree desc, tree offset, tree decl) { tree tmp; /* Class array references need special treatment because the assigned type size needs to be used to point to the element. */ if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc)) && TREE_CODE (desc) == COMPONENT_REF ! && GFC_CLASS_TYPE_P (TREE_TYPE (TREE_OPERAND (desc, 0)))) { ! tree type = gfc_get_element_type (TREE_TYPE (desc)); tmp = TREE_OPERAND (desc, 0); tmp = gfc_get_class_array_ref (offset, tmp); tmp = fold_convert (build_pointer_type (type), tmp); --- 3099,3118 ---- build_array_ref (tree desc, tree offset, tree decl) { tree tmp; + tree type; + + type = TREE_TYPE (TREE_OPERAND (desc, 0)); + if (TYPE_CANONICAL (type) + && GFC_CLASS_TYPE_P (TYPE_CANONICAL (type))) + type = TYPE_CANONICAL (type); /* Class array references need special treatment because the assigned type size needs to be used to point to the element. */ if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc)) && TREE_CODE (desc) == COMPONENT_REF ! && GFC_CLASS_TYPE_P (type)) { ! type = gfc_get_element_type (TREE_TYPE (desc)); tmp = TREE_OPERAND (desc, 0); tmp = gfc_get_class_array_ref (offset, tmp); tmp = fold_convert (build_pointer_type (type), tmp); fixes it. As remarked in PR54990, I do not know why this regression has occurred. Evidently, GFC_CLASS_TYPE_P is not being transferred from the canonical type, whereas this was happening before the regression (or a new type was not being generated?). I will investigate more. I have taken this PR. Cheers Paul