From patchwork Thu Oct 13 10:35:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 119409 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 64EA1B6F86 for ; Thu, 13 Oct 2011 21:35:40 +1100 (EST) Received: (qmail 27823 invoked by alias); 13 Oct 2011 10:35:38 -0000 Received: (qmail 27782 invoked by uid 22791); 13 Oct 2011 10:35:37 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 13 Oct 2011 10:35:16 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 772972BB00C; Thu, 13 Oct 2011 06:35:15 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id brYmKG2c6PtW; Thu, 13 Oct 2011 06:35:15 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 659272BAFDA; Thu, 13 Oct 2011 06:35:15 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 61E1A92BF6; Thu, 13 Oct 2011 06:35:15 -0400 (EDT) Date: Thu, 13 Oct 2011 06:35:15 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Box associations for components without defaults in aggregates Message-ID: <20111013103515.GA2858@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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 Box associations are used to initialize aggregate components through the default value of the corresponding components, or through calls to initialization procedures. In general aggregates with such initializations cannot be built statically. With this patch the following must compile quietly: gcc -c -gnat05 p.adb --- procedure P is type A1 is array (1 .. 2, 1 .. 2) of Integer; A : A1; begin A := ((1 => 2, others => <>), (others => 0)); end P; Tested on x86_64-pc-linux-gnu, committed on trunk 2011-10-13 Ed Schonberg * exp_aggr.adb (Flatten): If a component association has a box, assume that aggregate is not static. (Safe_Aggregate): If a component association in a non-limited aggregate has a box, assume that it cannot be expanded in place. Index: exp_aggr.adb =================================================================== --- exp_aggr.adb (revision 179894) +++ exp_aggr.adb (working copy) @@ -3398,6 +3398,15 @@ begin Assoc := First (Component_Associations (N)); while Present (Assoc) loop + + -- If this is a box association, flattening is in general + -- not possible because at this point we cannot tell if the + -- default is static or even exists. + + if Box_Present (Assoc) then + return False; + end if; + Choice := First (Choices (Assoc)); while Present (Choice) loop @@ -4148,6 +4157,12 @@ return False; end if; + -- If association has a box, no way to determine yet + -- whether default can be assigned in place. + + elsif Box_Present (Expr) then + return False; + elsif not Safe_Component (Expression (Expr)) then return False; end if;