From 229a5164a7f7821457eaff5f1bc34987c7f1d04e Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 19 Aug 2026 13:17:10 +0100 Subject: [PATCH] Add warning for unused lables in `asm` templates --- src/check_asm.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/check_asm.cpp b/src/check_asm.cpp index 9be4bcd03..fe2f7d585 100644 --- a/src/check_asm.cpp +++ b/src/check_asm.cpp @@ -1502,6 +1502,9 @@ gb_internal void check_asm_instruction_operand(AsmCtx *asm_ctx, CheckerContext * error(expr, "Undeclared asm label '.%.*s'", LIT(name->token.string)); } name->entity = found; + if (found != nullptr) { + found->flags |= EntityFlag_Used; + } add_type_and_value(ctx, expr, Addressing_Value, found->type, {}); return; @@ -1844,6 +1847,14 @@ gb_internal void check_asm_template(AsmCtx *asm_ctx, CheckerContext *ctx, Entity } } + for (auto const &entry : ate->label_scope->elements) { + Entity *le = entry.value; + GB_ASSERT(le != nullptr); + if ((le->flags & EntityFlag_Used) == 0) { + warning(le->token, "'asm' label '.%.*s' is declared but never reference by any instruction", LIT(le->token.string)); + } + } + GB_ASSERT(entity->kind == Entity_AsmTemplate); if (results->Tuple.variables.count == 0 && !entity->AsmTemplate.is_volatile && !entity->AsmTemplate.clobber_memory &&