From patchwork Thu Nov 12 11:46:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 543320 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 DC1D31402D5 for ; Thu, 12 Nov 2015 22:46:53 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=wpnKxfTl; 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=SYkna/gvducGfUBFMwA+t9EJmsCYFDFONJHsgGtW6tswzzsHi2 L7sWunBnD34tmYacVVK4T/putRxME853oaRU0PRwJ16waKCVIW/UMundejZqOPw2 Pd8j8OkV5McoqO9CfqNmXvxZGXWZgR/qYrQbPlnqm8eZ5eWPD1X8gJcSc= 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=v+i3nPARdIByAkINjPpM6QjtRXY=; b=wpnKxfTlyoJpkjWqLsXZ e+DLGEim9UsVpUFdz1UptqPEnY+vCfAe7n+39UjKXcC1TH/NIKgx2ZHgQQx5VZzj FPAbqNVKcKpDxoOmTmmPinT2z/FDnYIt/3mQPB4jhKKcxRlm3HLWwAAG1t/H51CD IyDL9pcgZXYCF6PLu6nC0eI= Received: (qmail 83334 invoked by alias); 12 Nov 2015 11:46:46 -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 83322 invoked by uid 89); 12 Nov 2015 11:46:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 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; Thu, 12 Nov 2015 11:46:45 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 45DE429956; Thu, 12 Nov 2015 06:46:43 -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 zT-9NnrAFuLB; Thu, 12 Nov 2015 06:46:43 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 331F829955; Thu, 12 Nov 2015 06:46:43 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4192) id 3209F1A5; Thu, 12 Nov 2015 06:46:43 -0500 (EST) Date: Thu, 12 Nov 2015 06:46:43 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Crash on illegal selected component in synchronized body. Message-ID: <20151112114643.GA93338@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) The prefix of a selected component in a synchronized body cannot denote a component of the synchronized type unless the prefix is an entity name. This was not properly rejected before. Compiling bakery.adb must yield: bakery.adb:44:35: invalid reference to internal operation of some object of type "Bakery_Instance_Task" --- procedure Bakery is N : Natural := 10; -- Number of Processes [Customers] type Integer_Array is array (1 .. N) of Integer; type Ticket_And_Queue_Number is record R : Natural; -- Ticket Number [Lamport 'Number'] A : Natural; -- Queue Number [Lamport 'Choosing'] end record; task type Bakery_Instance_Task is entry Initialize(ID : Natural); end Bakery_Instance_Task; Bakery_Array : array (1 .. N) of Bakery_Instance_Task; task body Bakery_Instance_Task is R : Natural; -- This task's current ticket number [Lamport 'Number'] A : Integer_Array := (1 .. N => 0); ID0 : Natural; TQN : Ticket_And_Queue_Number; function Read_TQN(J : in Natural) return Ticket_And_Queue_Number is TQN : Ticket_And_Queue_Number; begin TQN := (R => R, A => A(J)); return TQN; end Read_TQN; begin accept Initialize(ID : Natural) do R := 0; A := (1 .. N => 0); ID0 := ID; end Initialize; -- Start R := 1; A(ID0) := 1; for J in 1 .. N loop if J /= ID0 then TQN := Bakery_Array(J).Read_TQN(J => J); end if; end loop; end Bakery_Instance_Task; begin for I in 1 .. N loop Bakery_Array(I).Initialize(ID => I); end loop; end Bakery; Tested on x86_64-pc-linux-gnu, committed on trunk 2015-11-12 Ed Schonberg * sem_ch4.adb (Analyze_Selected_Component): Diagnose an attempt to reference an internal entity from a synchronized type from within the body of that type, when the prefix of the selected component is not the current instance. Index: sem_ch4.adb =================================================================== --- sem_ch4.adb (revision 230241) +++ sem_ch4.adb (working copy) @@ -4655,6 +4655,23 @@ Comp = First_Private_Entity (Base_Type (Prefix_Type)); end loop; + -- If the scope is a current instance, the prefix cannot be an + -- expression of the same type (that would represent an attempt + -- to reach an internal operation of another synchronized object). + -- This is legal if prefix is an access to such type and there is + -- a dereference. + + if In_Scope + and then not Is_Entity_Name (Name) + and then Nkind (Name) /= N_Explicit_Dereference + then + Error_Msg_NE ("invalid reference to internal operation " + & "of some object of type&", N, Type_To_Use); + Set_Entity (Sel, Any_Id); + Set_Etype (Sel, Any_Type); + return; + end if; + -- If there is no visible entity with the given name or none of the -- visible entities are plausible interpretations, check whether -- there is some other primitive operation with that name.