From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70046 invoked by alias); 25 Apr 2017 10:39:12 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 70031 invoked by uid 89); 25 Apr 2017 10:39:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=di, dm, dg, UD:L 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, 25 Apr 2017 10:39:10 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 568F8358D; Tue, 25 Apr 2017 06:39:11 -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 oxpRbXcmTgtP; Tue, 25 Apr 2017 06:39:11 -0400 (EDT) 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 441933506; Tue, 25 Apr 2017 06:39:11 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 406BF3F0; Tue, 25 Apr 2017 06:39:11 -0400 (EDT) Date: Tue, 25 Apr 2017 10:47:00 -0000 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [Ada] Failure to detect illegal pragma No_Return Message-ID: <20170425103911.GA19098@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="vtzGhvizbBRQ85DL" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2017-04/txt/msg01152.txt.bz2 --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1075 A pragma No_Return that applies to a procedure body is illegal. This patch fixes a bug that caused the compiler to fail to give an error. The following test should get an error: no_return.adb:6:04: representation item appears too late package No_Return is procedure P; end No_Return; package body No_Return is procedure P is begin null; end P; pragma No_Return(P); end No_Return; Tested on x86_64-pc-linux-gnu, committed on trunk 2017-04-25 Bob Duff * sem_prag.adb (No_Return): Give an error if the pragma applies to a body. Specialize the error for the specless body case, as is done for (e.g.) pragma Convention. * debug.adb: Add switch -gnatd.J to disable the above legality checks. This is mainly for use in our test suite, to avoid rewriting a lot of illegal (but working) code. It might also be useful to customers. Under this switch, if a pragma No_Return applies to a body, and the procedure raises an exception (as it should), the pragma has no effect. If the procedure does return, execution is erroneous. --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=difs Content-length: 4766 Index: debug.adb =================================================================== --- debug.adb (revision 247177) +++ debug.adb (working copy) @@ -127,7 +127,7 @@ -- d.G Ignore calls through generic formal parameters for elaboration -- d.H GNSA mode for ASIS -- d.I Do not ignore enum representation clauses in CodePeer mode - -- d.J + -- d.J Relaxed rules for pragma No_Return -- d.K Enable generation of contract-only procedures in CodePeer mode -- d.L Depend on back end for limited types in if and case expressions -- d.M Relaxed RM semantics @@ -645,6 +645,11 @@ -- cases being able to change this default might be useful to remove -- some false positives. + -- d.J Relaxed rules for pragma No_Return. A pragma No_Return is illegal + -- if it applies to a body. This switch disables the legality check + -- for that. If the procedure does in fact return normally, execution + -- is erroneous, and therefore unpredictable. + -- d.K Enable generation of contract-only procedures in CodePeer mode and -- report a warning on subprograms for which the contract-only body -- cannot be built. Currently reported on subprograms defined in Index: sem_prag.adb =================================================================== --- sem_prag.adb (revision 247177) +++ sem_prag.adb (working copy) @@ -7621,7 +7621,7 @@ end if; -- Check that we are not applying this to a specless body. Relax this - -- check if Relaxed_RM_Semantics to accomodate other Ada compilers. + -- check if Relaxed_RM_Semantics to accommodate other Ada compilers. if Is_Subprogram (E) and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body @@ -8084,8 +8084,8 @@ N_Subprogram_Body then Error_Pragma - ("pragma% requires separate spec" - & " and must come before body"); + ("pragma% requires separate spec" & + " and must come before body"); end if; -- Test result type if given, note that the result type @@ -18177,6 +18177,29 @@ and then Scope (E) = Current_Scope loop if Ekind_In (E, E_Procedure, E_Generic_Procedure) then + -- Check that the pragma is not applied to a body. + -- First check the specless body case, to give a + -- different error message. These checks do not apply + -- if Relaxed_RM_Semantics, to accommodate other Ada + -- compilers. Disable these checks under -gnatd.J. + + if not Debug_Flag_Dot_JJ then + if Nkind (Parent (Declaration_Node (E))) = + N_Subprogram_Body + and then not Relaxed_RM_Semantics + then + Error_Pragma + ("pragma% requires separate spec" & + " and must come before body"); + end if; + + -- Now the "specful" body case + + if Rep_Item_Too_Late (E, N) then + raise Pragma_Exit; + end if; + end if; + Set_No_Return (E); -- A pragma that applies to a Ghost entity becomes Ghost @@ -26125,7 +26148,7 @@ raise Program_Error; end if; - -- To accomodate partial decoration of disabled SPARK features, this + -- To accommodate partial decoration of disabled SPARK features, this -- routine may be called with illegal input. If this is the case, do -- not raise Program_Error. @@ -28031,7 +28054,7 @@ (Item => First (Choices (Clause)), Is_Input => False); - -- To accomodate partial decoration of disabled SPARK features, this + -- To accommodate partial decoration of disabled SPARK features, this -- routine may be called with illegal input. If this is the case, do -- not raise Program_Error. @@ -28105,7 +28128,7 @@ end loop; end if; - -- To accomodate partial decoration of disabled SPARK features, this + -- To accommodate partial decoration of disabled SPARK features, this -- routine may be called with illegal input. If this is the case, do -- not raise Program_Error. --vtzGhvizbBRQ85DL--