Add warning for unused lables in asm templates

This commit is contained in:
gingerBill
2026-08-19 13:17:10 +01:00
parent 5917d5db6e
commit 229a5164a7

View File

@@ -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 &&