From patchwork Wed Jun 22 10:00:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 639067 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 3rZKqN45qYz9t1H for ; Wed, 22 Jun 2016 20:01:04 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=SJE/4uDy; 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=O0YoaCEdMboMFhT5ZOMknSSNmM6VezUpPrr4dsC8gcAxWrPpc4 rW6tp1jZCOYC18QzHmIDK04+zoHexo3saN6kE65Mrmxal27kUB1jRKmvhZXARD2D euzcxH/IYWdBbTT4isBf/tzWQMNIi2qrceXWbTkfOG9n/Mwzgm2NIjs3A= 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=E894Km8SvQHhoTOIASjEswPjXMA=; b=SJE/4uDycE5GcwE2ni8d zTZrote/YSbobp/IYAL9w3MwZy2WnQs5Eighmvpj/8bW1Rz/Eat91IfTLRBzGM4T gB27vb2gDl9mUOTjOGPJ2zPa5zq11VeopQytnwWBtNeffmXuj7rYFyWjsK5gtyEF 7Gx25dGkUxDb6Aw99n1SHxE= Received: (qmail 123381 invoked by alias); 22 Jun 2016 10:00:43 -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 123346 invoked by uid 89); 22 Jun 2016 10:00:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2168, freeze, UD:sem_ch13.adb, sem_ch13adb 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, 22 Jun 2016 10:00:32 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id F269D116601; Wed, 22 Jun 2016 06:00:30 -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 Rrefyqr0gIuT; Wed, 22 Jun 2016 06:00:30 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id DA72D116543; Wed, 22 Jun 2016 06:00:30 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id D967146C; Wed, 22 Jun 2016 06:00:30 -0400 (EDT) Date: Wed, 22 Jun 2016 06:00:30 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Crash on illegal expression in context with predicate Message-ID: <20160622100030.GA26642@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This patch fixes a compiler abort on a return statement for a function whose type is a derived type with a dynamic predicate, when the return expression has the parent type. Compiling gpr2-attribute.adb must yield: gpr2-attribute.adb:8:14: expected type "Qualified_Name" defined at gpr2-attribute.ads:12 gpr2-attribute.adb:8:14: found type "Standard.String" --- package GPR2 is subtype Name_Type is String with Dynamic_Predicate => Name_Type'Length > 0; end GPR2; -- with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; package GPR2.Attribute is type Qualified_Name (<>) is private; function Create (Name : Name_Type) return Qualified_Name; private type Qualified_Name is new Name_Type; end GPR2.Attribute; -- package body GPR2.Attribute is function Create (Name : Name_Type) return Qualified_Name is begin -- OK: return Qualified_Name (Name); -- with below code (missing conversion) GNAT crashes return Name; end Create; end GPR2.Attribute; Tested on x86_64-pc-linux-gnu, committed on trunk 2016-06-22 Ed Schonberg * sem_ch13.adb (Is_Predicate_Static): An inherited predicate can be static only if it applies to a scalar type. Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 237680) +++ sem_ch13.adb (working copy) @@ -8552,8 +8552,7 @@ Expression => Expr)))); -- If declaration has not been analyzed yet, Insert declaration - -- before freeze node. - -- Insert body after freeze node. + -- before freeze node. Insert body itself after freeze node. if not Analyzed (FDecl) then Insert_Before_And_Analyze (N, FDecl); @@ -11644,9 +11643,11 @@ -- to specify a static predicate for a subtype which is inheriting a -- dynamic predicate, so the static predicate validation here ignores -- the inherited predicate even if it is dynamic. + -- In all cases, a static predicate can only apply to a scalar type. elsif Nkind (Expr) = N_Function_Call and then Is_Predicate_Function (Entity (Name (Expr))) + and then Is_Scalar_Type (Etype (First_Entity (Entity (Name (Expr))))) then return True;