diff mbox

[Ada] Add assertion for context of subprograms

Message ID 3254671.4ZAudv9KGi@polaris
State New
Headers show

Commit Message

Eric Botcazou Feb. 8, 2015, 9:08 a.m. UTC
This adds an early assertion that the context of subprograms is in keeping 
with their scope, to avoid obscure segfaults later if this isn't the case.

Tested on x86_64-suse-linux, applied on the mainline.


2015-02-08  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/utils.c (begin_subprog_body): Assert that the body is
	present in the same context as the declaration.
diff mbox

Patch

Index: gcc-interface/utils.c
===================================================================
--- gcc-interface/utils.c	(revision 220502)
+++ gcc-interface/utils.c	(working copy)
@@ -3105,6 +3105,11 @@  begin_subprog_body (tree subprog_decl)
   /* This function is being defined.  */
   TREE_STATIC (subprog_decl) = 1;
 
+  /* The failure of this assertion will likely come from a wrong context for
+     the subprogram body, e.g. another procedure for a procedure declared at
+     library level.  */
+  gcc_assert (current_function_decl == decl_function_context (subprog_decl));
+
   current_function_decl = subprog_decl;
 
   /* Enter a new binding level and show that all the parameters belong to