Fix race condition with code_gen_module

This commit is contained in:
gingerBill
2026-03-15 21:35:02 +00:00
parent 2de214418c
commit 38d7f45e64
2 changed files with 6 additions and 5 deletions

View File

@@ -250,7 +250,7 @@ struct DeclInfo {
i64 variadic_reuse_max_align;
// NOTE(bill): this is to prevent a race condition since these procedure literals can be created anywhere at any time
struct lbModule *code_gen_module;
std::atomic<struct lbModule *> code_gen_module;
};
// ProcInfo stores the information needed for checking a procedure

View File

@@ -498,10 +498,11 @@ gb_internal lbModule *lb_module_of_expr(lbGenerator *gen, Ast *expr) {
gb_internal lbModule *lb_module_of_entity_internal(lbGenerator *gen, Entity *e, lbModule *curr_module) {
lbModule **found = nullptr;
if (e->kind == Entity_Procedure &&
e->decl_info &&
e->decl_info->code_gen_module) {
return e->decl_info->code_gen_module;
if (e->kind == Entity_Procedure && e->decl_info) {
lbModule *mod = e->decl_info->code_gen_module.load(std::memory_order_relaxed);
if (mod) {
return mod;
}
}
if (e->file) {
found = map_get(&gen->modules, cast(void *)e->file);