From patchwork Wed Nov 18 09:38:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 545932 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 7530214145C for ; Wed, 18 Nov 2015 20:39:11 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=rTrMycgj; 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=RFaeCh0yh1F+7hqD2qPMPQrtzMj8C5DXuxkNI56r8f9NqqEIH4 /k4cvUHtnNV44n/uLVtV8uMj/J/3cj/3OkSS16txBeRvdUt0orSVeIDGGwlFLrFt USrVl5U7MnSmrwTqwf6/eYWMV8QPdlQPYLGIgvXZE2YsvE/trXFC/Kx0s= 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=KDYLsGwtFcwge0PMfQ6DYUCyBdc=; b=rTrMycgj/LChRnZd9tbQ wbkGTwSFW3vhlRHczPQB4VKiO2VDdxQqiOEHotBMUr5/UQwYBoRzHWE3QrkzU/oF prbk5NkcpsnHsGJUE7nE5Hm28DoQAIN0QoXqD1rTHUceXNmuLVKzHCbK+ENuej+O x9Lf2yD5FrIlrKH7K9V+o14= Received: (qmail 85051 invoked by alias); 18 Nov 2015 09:39:01 -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 85032 invoked by uid 89); 18 Nov 2015 09:39:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.1 required=5.0 tests=BAYES_20, 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 09:38:56 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 0FAEA28D92; Wed, 18 Nov 2015 04:38:55 -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 6HVr0S8zzUBr; Wed, 18 Nov 2015 04:38:54 -0500 (EST) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id EEE5329464; Wed, 18 Nov 2015 04:38:54 -0500 (EST) Received: by tron.gnat.com (Postfix, from userid 4192) id E9DB236E; Wed, 18 Nov 2015 04:38:54 -0500 (EST) Date: Wed, 18 Nov 2015 04:38:54 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Hristian Kirtchev Subject: [Ada] Missing error on volatile return type of non-volatile function Message-ID: <20151118093854.GA94212@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This patch modifies the predicate which determines whether a function is volatile to correctly recognize a protected function. ------------ -- Source -- ------------ -- vol_func.ads package Vol_Func with SPARK_Mode is protected type Prot is end Prot; type Vol_Typ is null record with Volatile; function F (X : Prot) return Vol_Typ; function G return Vol_Typ; end Vol_Func; ---------------------------- -- Compilation and output -- ---------------------------- $ gcc -c vol_func.ads vol_func.ads:7:16: nonvolatile function "F" cannot have a volatile parameter vol_func.ads:7:33: nonvolatile function "F" cannot have a volatile return type vol_func.ads:8:33: nonvolatile function "G" cannot have a volatile return type Tested on x86_64-pc-linux-gnu, committed on trunk 2015-11-18 Hristian Kirtchev * sem_util.adb (Check_Nonvolatile_Function_Profile): Place the error message concerning the return type on the result definition. (Is_Volatile_Function): A function with a parameter of a protected type is a protected function if it is defined within a protected definition. Index: sem_util.adb =================================================================== --- sem_util.adb (revision 230521) +++ sem_util.adb (working copy) @@ -3120,9 +3120,9 @@ -- Inspect the return type if Is_Effectively_Volatile (Etype (Func_Id)) then - Error_Msg_N + Error_Msg_NE ("nonvolatile function & cannot have a volatile return type", - Func_Id); + Result_Definition (Parent (Func_Id)), Func_Id); end if; end Check_Nonvolatile_Function_Profile; @@ -14010,6 +14010,7 @@ if Is_Primitive (Func_Id) and then Present (First_Formal (Func_Id)) and then Is_Protected_Type (Etype (First_Formal (Func_Id))) + and then Etype (First_Formal (Func_Id)) = Scope (Func_Id) then return True;