From patchwork Sun Sep 19 13:05:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 65158 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 8559AB6EF2 for ; Sun, 19 Sep 2010 23:12:39 +1000 (EST) Received: (qmail 12229 invoked by alias); 19 Sep 2010 13:12:37 -0000 Received: (qmail 12218 invoked by uid 22791); 19 Sep 2010 13:12:36 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 19 Sep 2010 13:12:30 +0000 Received: from eggs.gnu.org ([140.186.70.92]:45179) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1OxJgy-0006B2-0H for gcc-patches@gnu.org; Sun, 19 Sep 2010 09:12:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OxJgv-0000Oa-VF for gcc-patches@gnu.org; Sun, 19 Sep 2010 09:12:27 -0400 Received: from mel.act-europe.fr ([212.99.106.210]:44915) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OxJgv-0000OM-Ns for gcc-patches@gnu.org; Sun, 19 Sep 2010 09:12:25 -0400 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 5EF32CB02A8 for ; Sun, 19 Sep 2010 15:12:24 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id eP3C2ocu+fKG for ; Sun, 19 Sep 2010 15:12:24 +0200 (CEST) Received: from [192.168.1.2] (bon31-9-83-155-120-49.fbx.proxad.net [83.155.120.49]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 2EAF0CB0202 for ; Sun, 19 Sep 2010 15:12:24 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gnu.org Subject: [Ada] lift arbitrary limitation on external constants Date: Sun, 19 Sep 2010 15:05:52 +0200 User-Agent: KMail/1.9.9 MIME-Version: 1.0 Message-Id: <201009191505.52561.ebotcazou@adacore.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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 Gigi looks into the defining expression of external constants, except for two cases: /* If we have an external constant that we are not defining, get the expression that is was defined to represent. We may throw that expression away later if it is not a constant. Do not retrieve the expression if it is an aggregate or allocator, because in complex instantiation contexts it may not be expanded */ if (!definition && Present (Expression (Declaration_Node (gnat_entity))) && !No_Initialization (Declaration_Node (gnat_entity)) && (Nkind (Expression (Declaration_Node (gnat_entity))) != N_Aggregate) && (Nkind (Expression (Declaration_Node (gnat_entity))) != N_Allocator)) gnu_expr = gnat_to_gnu (Expression (Declaration_Node (gnat_entity))); The first limitation is somewhat bogus: if you have a qualified aggregate, it is bypassed and we have tests that fail if gigi doesn't fold the qualified aggregate, because of additional elaboration code. The attached patch lifts this limitation. Tested on i586-suse-linux, applied on the mainline. 2010-09-19 Eric Botcazou * gcc-interface/decl.c (gnat_to_gnu_entity) : Look into expressions for external constants that are aggregates. * gcc-interface/utils2.c (build_simple_component_ref): If the field is an inherited component in an extension, look through the extension. 2010-09-19 Eric Botcazou * gnat.dg/specs/constant1.ads: New test. * gnat.dg/specs/constant1_pkg.ads: New helper. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 167578) +++ gcc-interface/decl.c (revision 167579) @@ -421,17 +421,15 @@ gnat_to_gnu_entity (Entity_Id gnat_entit } /* If we have an external constant that we are not defining, get the - expression that is was defined to represent. We may throw that - expression away later if it is not a constant. Do not retrieve the - expression if it is an aggregate or allocator, because in complex - instantiation contexts it may not be expanded */ + expression that is was defined to represent. We may throw it away + later if it is not a constant. But do not retrieve the expression + if it is an allocator because the designated type might be dummy + at this point. */ if (!definition - && Present (Expression (Declaration_Node (gnat_entity))) && !No_Initialization (Declaration_Node (gnat_entity)) - && (Nkind (Expression (Declaration_Node (gnat_entity))) - != N_Aggregate) - && (Nkind (Expression (Declaration_Node (gnat_entity))) - != N_Allocator)) + && Present (Expression (Declaration_Node (gnat_entity))) + && Nkind (Expression (Declaration_Node (gnat_entity))) + != N_Allocator) gnu_expr = gnat_to_gnu (Expression (Declaration_Node (gnat_entity))); /* Ignore deferred constant definitions without address clause since Index: gcc-interface/utils2.c =================================================================== --- gcc-interface/utils2.c (revision 167578) +++ gcc-interface/utils2.c (revision 167579) @@ -1603,10 +1603,9 @@ build_simple_component_ref (tree record_ if (!field) return NULL_TREE; - /* If this field is not in the specified record, see if we can find - something in the record whose original field is the same as this one. */ + /* If this field is not in the specified record, see if we can find a field + in the specified record whose original field is the same as this one. */ if (DECL_CONTEXT (field) != record_type) - /* Check if there is a field with name COMPONENT in the record. */ { tree new_field; @@ -1616,6 +1615,21 @@ build_simple_component_ref (tree record_ if (SAME_FIELD_P (field, new_field)) break; + /* Next, see if we're looking for an inherited component in an extension. + If so, look thru the extension directly. */ + if (!new_field + && TREE_CODE (record_variable) == VIEW_CONVERT_EXPR + && TYPE_ALIGN_OK (record_type) + && TREE_CODE (TREE_TYPE (TREE_OPERAND (record_variable, 0))) + == RECORD_TYPE + && TYPE_ALIGN_OK (TREE_TYPE (TREE_OPERAND (record_variable, 0)))) + { + ref = build_simple_component_ref (TREE_OPERAND (record_variable, 0), + NULL_TREE, field, no_fold_p); + if (ref) + return ref; + } + /* Next, loop thru DECL_INTERNAL_P components if we haven't found the component in the first search. Doing this search in 2 steps is required to avoiding hidden homonymous fields in the