From patchwork Wed Nov 18 10:32:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 545947 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 3064414145C for ; Wed, 18 Nov 2015 21:32:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=fZWRfvXI; 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=Ejag9+rpuJCTpbR912XChnJNL49S1fOdEtwI+yF4U86JvqnDwe y473Ymy80k0ZjjZZKqRRx2wYTACl2fpc4HdWFnEhJUj6+/+gU2shkbbWJrXNP7G8 aDBiTG25T8wlWCGcWyb3tvJMHn6zurbIt1hjS0PT3IjbZ3pz0zyMLPDN0= 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=lMnCICe6+PP5QXgnHfbdBs8FFq8=; b=fZWRfvXIszYAGz6MDuN2 uBBtifj29v3CZ7fe/BcIXN8AFFtjAD0zXKrNcot13Z/O4Ao1VcRb8rK/8JjOys+n liC489tE5BlVw8iYN5IGUqgk+lP2SRbqR6KJgT8xnU4NtURO1GhOQVo+CUwi0dCE EDcZFDBtuoJmhguT3mruR4k= Received: (qmail 21452 invoked by alias); 18 Nov 2015 10:32:05 -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 21434 invoked by uid 89); 18 Nov 2015 10:32:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=AWL, BAYES_50, KAM_ASCII_DIVIDERS, 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; Wed, 18 Nov 2015 10:32:03 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 1052529529; Wed, 18 Nov 2015 05:32:02 -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 qufrmp5YdcGA; Wed, 18 Nov 2015 05:32:02 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id E4B7F29527; Wed, 18 Nov 2015 05:32:01 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4192) id DD7D436E; Wed, 18 Nov 2015 05:32:01 -0500 (EST) Date: Wed, 18 Nov 2015 05:32:01 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Crash on illegal use of limited view of classwide type Message-ID: <20151118103201.GA88311@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 attempt to assign to a record component whose type is the limited view of a classwide type. Compiling gcc -c c3a1004e.adb must yield: c3a1004e.adb:9:07: invalid use of limited view of "Department'CLASS" --- limited with C3A1004E; package C3A1004D is -- Departments type Emp_Ptr is access all C3A1004E.Employee'Class; type Department is tagged private; private subtype Dept_Name is String (1 .. 13); type T_List is array (Positive range <>) of Emp_Ptr; type Department is tagged record Id : Dept_Name := "<>"; List : T_List (1 .. 5); Tot : Natural := 0; During_Mod : Boolean := False; end record; end C3A1004D; --- package C3A1004E.Stub_Data is type C3A1004D_Department_Class_Access is access all C3A1004D.Department'Class; type Stub_Data_Type_Assign_Employee_dacb0f_a2752f is record D : C3A1004D_Department_Class_Access; end record; Stub_Data_Assign_Employee_dacb0f_a2752f : Stub_Data_Type_Assign_Employee_dacb0f_a2752f; end C3A1004E.Stub_Data; --- with C3A1004E.Stub_Data; use C3A1004E.Stub_Data; -- with C3A1004D; -- missing package body C3A1004E is procedure Assign_Employee (E : in out Employee; D : in out C3A1004D.Department'Class) is begin D := Stub_Data.Stub_Data_Assign_Employee_dacb0f_a2752f.D.all; end Assign_Employee; end C3A1004E; --- limited with C3A1004D; package C3A1004E is -- Employees type Dept_Ptr is access all C3A1004D.Department'Class; type Employee is tagged private; type Emp_Ptr is access all Employee'Class; -- used by function 'hire' procedure Assign_Employee (E : in out Employee; D : in out C3A1004D.Department'Class); private type Employee is tagged record Dept : Dept_Ptr; Id : access String; During_Mod : Boolean := False; end record; end C3A1004E; Tested on x86_64-pc-linux-gnu, committed on trunk 2015-11-18 Ed Schonberg * sem_ch5.adb (Analyze_Assignment): Diagnose assignment where left-hand side has a limited view of a class-wide type. * sem_ch6.adb (Detected_And_Exchange): Do not install a non-limited view if the scope of the type of the formal is visible through a limited_with_clause, even if the non-limited view is available. Index: sem_ch5.adb =================================================================== --- sem_ch5.adb (revision 230522) +++ sem_ch5.adb (working copy) @@ -506,6 +506,15 @@ Ghost_Mode := Save_Ghost_Mode; return; + -- A class-wide type may be a limited view. This illegal case is not + -- caught by previous checks. + + elsif Ekind (T1) = E_Class_Wide_Type + and then From_Limited_With (T1) + then + Error_Msg_NE ("invalid use of limited view of&", Lhs, T1); + return; + -- Enforce RM 3.9.3 (8): the target of an assignment operation cannot be -- abstract. This is only checked when the assignment Comes_From_Source, -- because in some cases the expander generates such assignments (such Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 230526) +++ sem_ch6.adb (working copy) @@ -2786,7 +2786,10 @@ procedure Detect_And_Exchange (Id : Entity_Id); -- Determine whether Id's type denotes an incomplete type associated -- with a limited with clause and exchange the limited view with the - -- non-limited one when available. + -- non-limited one when available. Note that the non-limited view + -- may exist because of a with_clause in another unit in the context, + -- but cannot be used because the current view of the enclosing unit + -- is still a limited view. ------------------------- -- Detect_And_Exchange -- @@ -2795,7 +2798,10 @@ procedure Detect_And_Exchange (Id : Entity_Id) is Typ : constant Entity_Id := Etype (Id); begin - if From_Limited_With (Typ) and then Has_Non_Limited_View (Typ) then + if From_Limited_With (Typ) + and then Has_Non_Limited_View (Typ) + and then not From_Limited_With (Scope (Typ)) + then Set_Etype (Id, Non_Limited_View (Typ)); end if; end Detect_And_Exchange;