From patchwork Wed Nov 14 11:44:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 997637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-490008-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="qxuxsNea"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42w2lF0NnTz9s9G for ; Wed, 14 Nov 2018 22:46:32 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=Ma21TjFndRdNlHYJIsFVOi2I2ZBsh/0Og0tsRNC9p6tH/OUc/L ppd0ycdIknvQjeCFbWkyHZHqeDYAID2Q9218jhF8iRfC764zC73afqPYCyVsyfT8 nGUsirYd0QBTS24sAHBl2n5S7U4ZbMKVNM3Cs0h8yeLPatQAtXXaFjeJQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=JPCIgJh0u8ZJIOdzx3rOuQQAlDc=; b=qxuxsNeaBj8QVHpxjlB3 ABFthy3aBg6J2k4aJYsD1w8Mzz5E5PPLqXpOtM4nebqi2D3RIu3QZXEsNcH/x0NI eCxdoaq7Dy88C9WWndCx7uXXXJ+dfLsATj6DERmyebQVAjk2D6hAYBRmLbrPGoEy 7LwkPBbTMUq8+vL1Y4EmTRk= Received: (qmail 48856 invoked by alias); 14 Nov 2018 11:44:37 -0000 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 Received: (qmail 48777 invoked by uid 89); 14 Nov 2018 11:44:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=bellow, delayed X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 14 Nov 2018 11:44:35 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 00BC056158; Wed, 14 Nov 2018 06:44:34 -0500 (EST) 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 OrtTJoKQu+0Z; Wed, 14 Nov 2018 06:44:33 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id E421E560C3; Wed, 14 Nov 2018 06:44:33 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4862) id E33AC353A; Wed, 14 Nov 2018 06:44:33 -0500 (EST) Date: Wed, 14 Nov 2018 06:44:33 -0500 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Compiler crash on decl. with limited aggregate and address clause Message-ID: <20181114114433.GA74094@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes This patch fixes a compiler abort on an object declaration whose expression is an aggregate, when the type of the object is limited and the declaration is followed by an address clause for the declared object. Tested on x86_64-pc-linux-gnu, committed on trunk 2018-11-14 Ed Schonberg gcc/ada/ * exp_ch3.adb: (Expand_N_Object_Declaration): If the expression is a limited aggregate its resolution is delayed until the object declaration is expanded. * sem_ch3.adb: (Analyze_Object_Declaration): If the expression is a limited aggregate and the declaration has a following address clause indicate that resolution of the aggregate (which must be built in place) must be delayed. gcc/testsuite/ * gnat.dg/limited_aggr.adb, gnat.dg/limited_aggr.ads: New testcase. --- gcc/ada/exp_ch3.adb +++ gcc/ada/exp_ch3.adb @@ -6586,6 +6586,16 @@ package body Exp_Ch3 is -- thus avoid creating a temporary. if Is_Delayed_Aggregate (Expr_Q) then + + -- An aggregate that must be built in place is not resolved + -- and expanded until the enclosing construct is expanded. + -- This will happen when the aggregqte is limited and the + -- declared object has a following address clause. + + if Is_Limited_Type (Typ) and then not Analyzed (Expr) then + Resolve (Expr, Typ); + end if; + Convert_Aggr_In_Object_Decl (N); -- Ada 2005 (AI-318-02): If the initialization expression is a call @@ -7022,7 +7032,7 @@ package body Exp_Ch3 is -- Given that the type is limited we cannot perform a copy. If -- Expr_Q is the reference to a variable we mark the variable -- as OK_To_Rename to expand this declaration into a renaming - -- declaration (see bellow). + -- declaration (see below). if Is_Entity_Name (Expr_Q) then Set_OK_To_Rename (Entity (Expr_Q)); --- gcc/ada/sem_ch3.adb +++ gcc/ada/sem_ch3.adb @@ -4283,6 +4283,14 @@ package body Sem_Ch3 is then Set_Etype (E, T); + -- If the aggregate is limited it will be built in place, + -- and its expansion is deferred until the object declaration + -- is expanded. + + if Is_Limited_Type (T) then + Set_Expansion_Delayed (E); + end if; + else -- If the expression is a formal that is a "subprogram pointer" --- /dev/null new file mode 100644 +++ gcc/testsuite/gnat.dg/limited_aggr.adb @@ -0,0 +1,5 @@ +-- { dg-do compile } + +package body Limited_Aggr is + procedure Dummy is null; +end Limited_Aggr; --- /dev/null new file mode 100644 +++ gcc/testsuite/gnat.dg/limited_aggr.ads @@ -0,0 +1,10 @@ +package Limited_Aggr is + type R is limited record + F1, F2 : Integer; + end record; + X : array (1..2) of integer; + Y : R := (-111, -222); + for Y'Address use X'Address; + + procedure Dummy; +end Limited_Aggr;