From patchwork Mon Jan 20 15:35:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 312622 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 B01342C0082 for ; Tue, 21 Jan 2014 02:35:48 +1100 (EST) 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=ogTXRsXdMzW/CEN/TcOO4hIe3mbikFqkcuBbfsiMefHYpJO5X9 kvV2f5lyu2ZsbN7VwHYxG4K+/bHPmMdNDUDwr+SQv9mVaSyKF/h1BPFcwGLUVOrM Flj/a6ukGghvyRQkLssgWGHJHhm/MZugCMiU30H70EZeZVInwwGqeLJXY= 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=ws+9Qxfz54RqxnTHU3v6XjUvP54=; b=caa7M8EQkth9ao2y6wsD 0aAYZwNQEnhj44vGgV+/p7lRGKq+glfa948lFD3A6Ni4DTef7fkKFwFKPM6mTCRr PYebnSbjM9daCO7B7ZL7wZBpsx3S9dC+hy+q/6rubDYOv67rBtD75yQhBHKS/BPJ bHnpRGyfu2+9IzolC0gxsns= Received: (qmail 23400 invoked by alias); 20 Jan 2014 15:35:33 -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 23303 invoked by uid 89); 20 Jan 2014 15:35:32 -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; Mon, 20 Jan 2014 15:35:31 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 07A0B116358; Mon, 20 Jan 2014 10:35:30 -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 UVIUXTUJHE60; Mon, 20 Jan 2014 10:35:29 -0500 (EST) Received: from kwai.gnat.com (unknown [IPv6:2620:20:4000:0:a6ba:dbff:fe26:1f63]) by rock.gnat.com (Postfix) with ESMTP id 1B816116300; Mon, 20 Jan 2014 10:35:28 -0500 (EST) Received: by kwai.gnat.com (Postfix, from userid 4192) id 193E13FB31; Mon, 20 Jan 2014 10:35:28 -0500 (EST) Date: Mon, 20 Jan 2014 10:35:28 -0500 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Enabling assertions in predefined units Message-ID: <20140120153528.GA12352@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Some configuration switches that usually do not apply to predefined units, such as enabling assertion checking, can be applied to such a unit when they are the main unit and the switch is provided in the compilation command. When such a unit is a package body, the switch setting must apply as well to its spec. The following must execute quietly: gcc -c -gnatg s-libm.ads gcc -c -gnatg -gnata s-libaux.adb gnatmake -q -gnatws missedpost missedpost --- with System.Libm.Aux; use System.Libm.Aux; with Ada.Assertions; use Ada.Assertions; procedure Missedpost is X : Float := 0.866; begin P (X); if abs X >= 0.5 then raise Program_Error; end if; exception when Assertion_Error => null; end Missedpost; --- package body System.Libm.Aux is procedure P (X : in out Float) is begin X := (0.5 + X) * 0.5; end P; end System.Libm.Aux; --- package System.Libm.Aux is pragma Assertion_Policy (Postcondition => Check); procedure P (X : in out Float) with Post => abs X <= 0.5; end System.Libm.Aux; --- package System.Libm is end System.Libm; Tested on x86_64-pc-linux-gnu, committed on trunk 2014-01-20 Ed Schonberg * sem.adb (Semantics): When saving/restoring configuration switches, the spec of a pre- defined unit that is the main unit must be treated as a predefined unit as well. Index: sem.adb =================================================================== --- sem.adb (revision 206804) +++ sem.adb (working copy) @@ -1322,6 +1322,16 @@ -- If the main unit is generic, every compiled unit, including its -- context, is compiled with expansion disabled. + -- configuration flags have special settings when compiling a predefined + -- file as a main unit. This applies to its spec as well. + + Is_Main_Unit : constant Boolean := + Current_Sem_Unit = Main_Unit + or else + (Nkind (Unit (Cunit (Main_Unit))) = N_Package_Body + and then Library_Unit (Cunit (Main_Unit)) = + Cunit (Current_Sem_Unit)); + Ext_Main_Source_Unit : constant Boolean := In_Extended_Main_Source_Unit (Comp_Unit); -- Determine if unit is in extended main source unit @@ -1421,7 +1431,7 @@ Save_Opt_Config_Switches (Save_Config_Switches); Set_Opt_Config_Switches (Is_Internal_File_Name (Unit_File_Name (Current_Sem_Unit)), - Current_Sem_Unit = Main_Unit); + Is_Main_Unit); -- Save current non-partition-wide restrictions