From patchwork Mon Oct 9 21:03:23 2017 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: 823516 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-463825-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="e8J8fu8W"; 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 3y9t5H5L6Zz9t5Q for ; Tue, 10 Oct 2017 08:03:47 +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=aKwdJCg1TcXZUEx7H8KoKnI9RT1d6c69mCa96n1rqdAtJsZoCQ 2nutevC1RGrwUHbazRwt1bNF2nc+O1bAHkVFSxx3FGRemW4CF72G1gDwULqXInII CtzRdQ562iBnT7qxKf9RatJh06QelOclHxTfP53GPRIwKdVW38L7x8jds= 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=dF8qLg8oLu7HnKKXzwFeO71wXJE=; b=e8J8fu8WZU6f/9l1vy3K VhdZqPGzhTgoLxZIU9tH7sFB9MRcooXdHsX79RMLG/kNRwdlrvzsIhd6d4p9h6/v F9mhSY5phf1RjfCZJPhnITZ30S6+ecJQwwJscyeVbK5RVnNsjnVS8J4/q3iuXtnZ bZaCVaxJKx5Lv8U8Hd5IHb8= Received: (qmail 58314 invoked by alias); 9 Oct 2017 21:03:27 -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 58285 invoked by uid 89); 9 Oct 2017 21:03:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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= 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; Mon, 09 Oct 2017 21:03:25 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 06B2856330; Mon, 9 Oct 2017 17:03:24 -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 vYnRprtQ-alT; Mon, 9 Oct 2017 17:03:23 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id EA4E85632A; Mon, 9 Oct 2017 17:03:23 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4862) id E973643A; Mon, 9 Oct 2017 17:03:23 -0400 (EDT) Date: Mon, 9 Oct 2017 17:03:23 -0400 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Missing error on implicit copy of limited value in expression function Message-ID: <20171009210323.GA23838@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes This patch corrects an omission on the legality check of an allocator whose expression is of a limited type, when the allocator is the expression of an expression function. Compiling t3.adb must yield: t3.adb:4:13: warning: not dispatching (must be defined in a package spec) t3.adb:5:07: initialization not allowed for limited types --- procedure T3 is type X_T is tagged limited null record; type A_T is access X_T'Class; function Clone (X : X_T) return A_T is (new X_T'Class' (X_T'Class (X))); X : X_T; A : A_T := Clone (X); begin null; end T3; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-10-09 Ed Schonberg * sem_res.adb (Resolve_Allocator): Reject properly an allocator that attempts to copy a limited value, when the allocator is the expression in an expression function. Index: sem_res.adb =================================================================== --- sem_res.adb (revision 253563) +++ sem_res.adb (working copy) @@ -4834,10 +4834,18 @@ -- are explicitly marked as coming from source but do not need to be -- checked for limited initialization. To exclude this case, ensure -- that the parent of the allocator is a source node. + -- The return statement constructed for an Expression_Function does + -- not come from source but requires a limited check. if Is_Limited_Type (Etype (E)) and then Comes_From_Source (N) - and then Comes_From_Source (Parent (N)) + and then + (Comes_From_Source (Parent (N)) + or else + (Ekind (Current_Scope) = E_Function + and then Nkind + (Original_Node (Unit_Declaration_Node (Current_Scope))) + = N_Expression_Function)) and then not In_Instance_Body then if not OK_For_Limited_Init (Etype (E), Expression (E)) then