From patchwork Fri Jan 30 15:25:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 434947 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 EFB45140218 for ; Sat, 31 Jan 2015 02:26:37 +1100 (AEDT) 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=CmpjuEhQuo+/MCGgGhfwh6fficKJoWiiA31yzgRaMfzn95rtS+ lbev8wUkQqdLNfEhSAf6StFPZPUDETlCQD1rkYDYAnLBdY+Zrtt1//e+Ve5rdHT7 Zr+Wzf5I6UCZTvNhoiA3LEmkemUwHU//P7nCdGx7ritbX7zkaealqgUVM= 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=Z83xtD0mXEulgorrnzdcpdizPnE=; b=gRU8IoEyR7XMa9K5ZJLT btzesRy0f+TmYxmSWWL2oM5m/csB93cOj3OnCA3c132D6fl5zzliw/VcmWhX3ySV tjX/+G38qngUHZFo3xY7gw0SzAX5KMqNJ2TirOqdRiq+qV2SwuBSO5E4JeUUZPDc 50v4J1Kd9V+6jrcSnMynBTc= Received: (qmail 23097 invoked by alias); 30 Jan 2015 15:26:00 -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 23002 invoked by uid 89); 30 Jan 2015 15:25:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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; Fri, 30 Jan 2015 15:25:47 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id E0E8E1167FC; Fri, 30 Jan 2015 10:25:45 -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 JBvgITFM-PaD; Fri, 30 Jan 2015 10:25:45 -0500 (EST) Received: from kwai.gnat.com (kwai.gnat.com [IPv6:2620:20:4000:0:7a2b:cbff:fe60:cb11]) by rock.gnat.com (Postfix) with ESMTP id CD4761167F8; Fri, 30 Jan 2015 10:25:45 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id C9BFB3FE28; Fri, 30 Jan 2015 10:25:45 -0500 (EST) Date: Fri, 30 Jan 2015 10:25:45 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Robert Dewar Subject: [Ada] Suppress Import-In-Pure-Unit warning if Pure_Function given Message-ID: <20150130152545.GA29632@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) The warning for use of Import in a Pure unit is refined so that it is omitted if an explicit Pure_Function aspect is given, as shown by the following test, compiled with -gnatl 1. package PureImportF is 2. pragma Pure (PureImportF); 3. function F (A : integer) return integer; 4. pragma Import (C, F); | >>> warning: pragma Import in Pure unit >>> warning: calls to "F" may be omitted (RM 10.2.1(18/3)) 5. function F2 (A : integer) return integer; 6. pragma Pure_Function (F2); 7. pragma Import (C, F2); 8. end PureImportF; Tested on x86_64-pc-linux-gnu, committed on trunk 2015-01-30 Robert Dewar * freeze.adb (Freeze_Profile): Add test for suspicious import in pure unit. * sem_prag.adb (Process_Import_Or_Interface): Test for suspicious use in Pure unit is now moved to Freeze (to properly catch Pure_Function exemption). Index: freeze.adb =================================================================== --- freeze.adb (revision 220284) +++ freeze.adb (working copy) @@ -3081,6 +3081,44 @@ end if; end if; + -- Check suspicious use of Import in pure unit + + if Is_Imported (E) and then Is_Pure (Cunit_Entity (Current_Sem_Unit)) + + -- Ignore internally generated entity. This happens in some cases + -- of subprograms in specs, where we generate an implied body. + + and then Comes_From_Source (Import_Pragma (E)) + + -- Assume run-time knows what it is doing + + and then not GNAT_Mode + + -- Assume explicit Pure_Function means import is pure + + and then not Has_Pragma_Pure_Function (E) + + -- Don't need warning in relaxed semantics mode + + and then not Relaxed_RM_Semantics + + -- Assume convention Intrinsic is OK, since this is specialized. + -- This deals with the DEC unit current_exception.ads + + and then Convention (E) /= Convention_Intrinsic + + -- Assume that ASM interface knows what it is doing. This deals + -- with unsigned.ads in the AAMP back end. + + and then Convention (E) /= Convention_Assembler + then + Error_Msg_N + ("pragma Import in Pure unit??", Import_Pragma (E)); + Error_Msg_NE + ("\calls to & may be omitted (RM 10.2.1(18/3))??", + Import_Pragma (E), E); + end if; + return True; end Freeze_Profile;