From patchwork Tue Sep 12 09:12:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 812742 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-461898-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="lf25E34K"; 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 3xrzbP1Ttwz9s81 for ; Tue, 12 Sep 2017 19:12:48 +1000 (AEST) 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=uMv6e4zG1SujeuwU9pnTGdt1lShAnSJJOs1JopXcui2mpGpNFD I+IfIBlxExUYQ/fREbGUDKMtp4cBo0LHd/YnCnKEiqODwx/NoqCWtLKJXFdkJLKf Id44iocEmnq1TsQvqOpxRn0x8I589NNrgCkhO8oGBHiGQcyoRoDasJ+Vc= 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=ts2lLoO0TehbMtuG9ABiwfzWPXQ=; b=lf25E34KUsbVSfsvZlf/ t6Vezzko5OzoSNQFgigZhlb5u1quGQYgf8WWWRQAdGwrvv1JBLF6VsEkjnkSj1QA 3hq2oYGuQ5Ng8mBvdKLT6Ih/7AjF4lBDRESLmj2APkkWKNKoCaZ7jyBjDtkeiNyH ov46uaee69qRsNakR+JxKvM= Received: (qmail 30280 invoked by alias); 12 Sep 2017 09:12:40 -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 30262 invoked by uid 89); 12 Sep 2017 09:12:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, 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; Tue, 12 Sep 2017 09:12:38 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 1FEBD56040; Tue, 12 Sep 2017 05:12:37 -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 NjX3ZSQdpMkT; Tue, 12 Sep 2017 05:12:37 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id 0DCB356037; Tue, 12 Sep 2017 05:12:37 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 08105521; Tue, 12 Sep 2017 05:12:37 -0400 (EDT) Date: Tue, 12 Sep 2017 05:12:37 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [Ada] Dynamically tagged expr of expr function is illegal Message-ID: <20170912091237.GA64499@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) It is illegal to return a dynamically tagged expression from an expression function that returns a specific type. See RM-3.9.2(9). This patch fixes a bug that caused the compiler to fail to detect this illegality. Tested on x86_64-pc-linux-gnu, committed on trunk 2017-09-12 Bob Duff * sem_ch6.adb (Analyze_Expression_Function): Call Check_Dynamically_Tagged_Expression. * sem_util.adb (Check_Dynamically_Tagged_Expression): Remove "and then Is_Tagged_Type (Typ)" because there is an earlier "Assert (Is_Tagged_Type (Typ))". Index: sem_util.adb =================================================================== --- sem_util.adb (revision 251998) +++ sem_util.adb (working copy) @@ -2022,7 +2022,6 @@ or else In_Generic_Actual (Expr)) and then (Is_Class_Wide_Type (Etype (Expr)) or else Is_Dynamically_Tagged (Expr)) - and then Is_Tagged_Type (Typ) and then not Is_Class_Wide_Type (Typ) then Error_Msg_N ("dynamically tagged expression not allowed!", Expr); Index: sem_ch6.adb =================================================================== --- sem_ch6.adb (revision 251998) +++ sem_ch6.adb (working copy) @@ -741,6 +741,21 @@ end; end if; + -- Check incorrect use of dynamically tagged expression. This doesn't + -- fall out automatically when analyzing the generated function body, + -- because Check_Dynamically_Tagged_Expression deliberately ignores + -- nodes that don't come from source. + + if Present (Def_Id) + and then Nkind (Def_Id) in N_Has_Etype + and then Is_Tagged_Type (Etype (Def_Id)) + then + Check_Dynamically_Tagged_Expression + (Expr => Expr, + Typ => Etype (Def_Id), + Related_Nod => Original_Node (N)); + end if; + -- If the return expression is a static constant, we suppress warning -- messages on unused formals, which in most cases will be noise.