[Ada] Fix assertion failure on functions with contracts

Message ID 20200610133540.GA80637@adacore.com
State New
Headers show
Series
  • [Ada] Fix assertion failure on functions with contracts
Related show

Commit Message

Pierre-Marie de Rodat June 10, 2020, 1:35 p.m.
This commit fixes a bug introduced in a previous commit that attempted
to detect illegal body definitions on null procedures but did not
account for the fact that function definitions such as `function F
return Integer with Global => null is` could use the same path. This
would result in an assertion failure when Null_Present was called on the
function's specification.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-10  Ghjuvan Lacambre  <lacambre@adacore.com>

gcc/ada/

	* par-ch6.adb (P_Subprogram): Make sure the specification
	belongs to a procedure.

Patch

--- gcc/ada/par-ch6.adb
+++ gcc/ada/par-ch6.adb
@@ -960,9 +960,12 @@  package body Ch6 is
 
          if Token = Tok_Is then
 
-            --  If the subprogram declaration already has a specification, we
-            --  can't define another.
-            if Null_Present (Specification (Decl_Node)) then
+            --  If the subprogram is a procedure and already has a
+            --  specification, we can't define another.
+
+            if Nkind (Specification (Decl_Node)) = N_Procedure_Specification
+              and then Null_Present (Specification (Decl_Node))
+            then
                Error_Msg_AP ("null procedure cannot have a body");
             end if;