From patchwork Mon May 2 10:36:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 617463 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qz12v1rs1z9sRZ for ; Mon, 2 May 2016 20:37:27 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Lxxl8F3d; dkim-atps=neutral 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=n8GUJy4HXtAjgtKxmHlwOkuTP7dqkTBo3IinmvCtt8mpRupEt5 gTmr7vR85LsgNpVo/w7lCo8CxeeQY6DvJqDatSk0NdY2Gwh2I591Qk/LcNXzbtpF cX4dsaXE4lxFGyvVgTNQ269B6JCE2KrOGiOORxsaz4tUS5yM+j7uv7LiQ= 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=fjt1z3ra4WtxFHau75rd7iInHA0=; b=Lxxl8F3dKuGeWSWO7hCa Ytn7BYXJZjg0d6GR5PsRC0zb8maJCeR6gPpBy3FmociQVKlvBBlUzd/TOvQ86qd6 6f/8MwHYhEmhgXzUgh0K7uSWzoKVHs/RmudL1Ml4ju/Fkh21ey0sBfVyxtXF3B2k xej/XVCUVbnIBWf8poH0zV4= Received: (qmail 16307 invoked by alias); 2 May 2016 10:37:14 -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 16244 invoked by uid 89); 2 May 2016 10:37:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.3 required=5.0 tests=AWL, BAYES_50, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 spammy=Nkind, nkind, etype, Etype 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 (AES256-SHA encrypted) ESMTPS; Mon, 02 May 2016 10:36:59 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 2E392116B44; Mon, 2 May 2016 06:36:58 -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 2yxuMfto3YsF; Mon, 2 May 2016 06:36:58 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 1DF52116B3D; Mon, 2 May 2016 06:36:58 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 1CF7230C; Mon, 2 May 2016 06:36:58 -0400 (EDT) Date: Mon, 2 May 2016 06:36:58 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Crash on illegal allocator for limited type. Message-ID: <20160502103658.GA23343@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This patch fixes a compiler crash on an allocator for an object of a limited type, when the expression of the qualified expression is a type conversion. Compiling bug1.adb must yield: bug1.adb:29:08: illegal expression for initialized allocator of a limited type (RM 7.5 (2.7/2)) --- pragma Ada_2012; procedure Bug1 is package Interf is type T is limited interface; subtype Implementor is T'Class; function Init return T is abstract; end Interf; package Impl is type T is limited new Interf.T with private; overriding function Init return T; private type T is limited new Interf.T with null record; end Impl; package body Impl is function Init return T is begin return Obj : T do null; end return; end Init; end Impl; use Impl; V : access Interf.T'Class; Thing : T := Init; begin V := new Interf.T'class'(Interf.Implementor(Impl.Init)); end Bug1; Tested on x86_64-pc-linux-gnu, committed on trunk 2016-05-02 Ed Schonberg * sem_ch3.adb (OK_For_Limited_Init): A type conversion is not always legal in the in-place initialization of a limited entity (e.g. an allocator). * sem_res.adb (Resolve_Allocator): Improve error message with RM reference when allocator expression is illegal. Index: sem_ch3.adb =================================================================== --- sem_ch3.adb (revision 235740) +++ sem_ch3.adb (working copy) @@ -18656,11 +18656,14 @@ is begin -- An object of a limited interface type can be initialized with any - -- expression of a nonlimited descendant type. + -- expression of a nonlimited descendant type. However this does not + -- apply if this is a view conversion of some other expression. This + -- is checked below. if Is_Class_Wide_Type (Typ) and then Is_Limited_Interface (Typ) and then not Is_Limited_Type (Etype (Exp)) + and then Nkind (Exp) /= N_Type_Conversion then return True; end if; Index: sem_res.adb =================================================================== --- sem_res.adb (revision 235714) +++ sem_res.adb (working copy) @@ -4767,13 +4767,21 @@ and then not In_Instance_Body then if not OK_For_Limited_Init (Etype (E), Expression (E)) then - Error_Msg_N ("initialization not allowed for limited types", N); + if Nkind (Parent (N)) = N_Assignment_Statement then + Error_Msg_N + ("illegal expression for initialized allocator of a " + & "limited type (RM 7.5 (2.7/2))", N); + else + Error_Msg_N + ("initialization not allowed for limited types", N); + end if; + Explain_Limited_Type (Etype (E), N); end if; end if; - -- A qualified expression requires an exact match of the type. - -- Class-wide matching is not allowed. + -- A qualified expression requires an exact match of the type. Class- + -- wide matching is not allowed. if (Is_Class_Wide_Type (Etype (Expression (E))) or else Is_Class_Wide_Type (Etype (E)))