Browse Source

Forbid nested declaration of instrumentation procedures

Fixes #3774
Feoramund 2 months ago
parent
commit
3608297e0b
1 changed files with 6 additions and 0 deletions
  1. 6 0
      src/check_decl.cpp

+ 6 - 0
src/check_decl.cpp

@@ -1341,6 +1341,9 @@ gb_internal void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
 			error(e->token, "@(instrumentation_enter) procedures must have the type '%s', got %s", instrumentation_proc_type_str, s);
 			error(e->token, "@(instrumentation_enter) procedures must have the type '%s', got %s", instrumentation_proc_type_str, s);
 			gb_string_free(s);
 			gb_string_free(s);
 		}
 		}
+		if ((e->scope->flags & (ScopeFlag_File|ScopeFlag_Pkg)) == 0) {
+			error(e->token, "@(instrumentation_enter) procedures must be declared at the file scope");
+		}
 		MUTEX_GUARD(&ctx->info->instrumentation_mutex);
 		MUTEX_GUARD(&ctx->info->instrumentation_mutex);
 		if (ctx->info->instrumentation_enter_entity != nullptr) {
 		if (ctx->info->instrumentation_enter_entity != nullptr) {
 			error(e->token, "@(instrumentation_enter) has already been set");
 			error(e->token, "@(instrumentation_enter) has already been set");
@@ -1357,6 +1360,9 @@ gb_internal void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
 			error(e->token, "@(instrumentation_exit) procedures must have the type '%s', got %s", instrumentation_proc_type_str, s);
 			error(e->token, "@(instrumentation_exit) procedures must have the type '%s', got %s", instrumentation_proc_type_str, s);
 			gb_string_free(s);
 			gb_string_free(s);
 		}
 		}
+		if ((e->scope->flags & (ScopeFlag_File|ScopeFlag_Pkg)) == 0) {
+			error(e->token, "@(instrumentation_exit) procedures must be declared at the file scope");
+		}
 		MUTEX_GUARD(&ctx->info->instrumentation_mutex);
 		MUTEX_GUARD(&ctx->info->instrumentation_mutex);
 		if (ctx->info->instrumentation_exit_entity != nullptr) {
 		if (ctx->info->instrumentation_exit_entity != nullptr) {
 			error(e->token, "@(instrumentation_exit) has already been set");
 			error(e->token, "@(instrumentation_exit) has already been set");