aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2025-06-23 18:33:04 +0200
committerGitHub <noreply@github.com>2025-06-23 18:33:04 +0200
commit8846372053f61a0d3d80bc55222b02c6fd928bf8 (patch)
tree6f3f5fb74fa78f0696d8a4eaeafbcb949d907b71
parentbe3f8e3c9d03d686c64fbbab97b7950c2c325861 (diff)
parent3608297e0b8186635b8f52d6c95b16cf6c8f4b7a (diff)
Merge pull request #5396 from Feoramund/fix-3774
Forbid nested declaration of instrumentation procedures
-rw-r--r--src/check_decl.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index c696fc4c1..3d0d95556 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -1334,12 +1334,16 @@ gb_internal void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
has_instrumentation = false;
e->flags |= EntityFlag_Require;
} else if (ac.instrumentation_enter) {
+ init_core_source_code_location(ctx->checker);
if (!is_valid_instrumentation_call(e->type)) {
init_core_source_code_location(ctx->checker);
gbString s = type_to_string(e->type);
error(e->token, "@(instrumentation_enter) procedures must have the type '%s', got %s", instrumentation_proc_type_str, 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);
if (ctx->info->instrumentation_enter_entity != nullptr) {
error(e->token, "@(instrumentation_enter) has already been set");
@@ -1356,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);
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);
if (ctx->info->instrumentation_exit_entity != nullptr) {
error(e->token, "@(instrumentation_exit) has already been set");