diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 9f832bd29..1d949aacf 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -1724,6 +1724,7 @@ struct SemaContext_ Decl** locals; DynamicScope active_scope; Expr *return_expr; + bool is_temp; }; typedef struct diff --git a/src/compiler/llvm_codegen_module.c b/src/compiler/llvm_codegen_module.c index 584ec0803..a33d518d6 100644 --- a/src/compiler/llvm_codegen_module.c +++ b/src/compiler/llvm_codegen_module.c @@ -60,7 +60,7 @@ void gencontext_begin_module(GenContext *c) ASSERT0(!c->module && "Expected no module"); codegen_setup_object_names(c->code_module, &c->ir_filename, &c->asm_filename, &c->object_filename); - + DEBUG_LOG("Emit module %s.", c->code_module->name->module); c->panic_var = compiler.context.panic_var; c->panicf = compiler.context.panicf; c->module = LLVMModuleCreateWithNameInContext(c->code_module->name->module, c->context); diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 72575983f..16795d10c 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1362,6 +1362,12 @@ static bool sema_analyse_parameter(SemaContext *context, Expr *arg, Decl *param, break; case VARDECL_PARAM_EXPR: // #foo + if (context->is_temp) + { + SemaContext *temp = context; + context = MALLOCS(SemaContext); + *context = *temp; + } param->var.hash_var.context = context; param->var.hash_var.span = arg->span; break; diff --git a/src/compiler/semantic_analyser.c b/src/compiler/semantic_analyser.c index 5df72f52e..59b4cda2c 100644 --- a/src/compiler/semantic_analyser.c +++ b/src/compiler/semantic_analyser.c @@ -529,6 +529,7 @@ SemaContext *context_transform_for_eval(SemaContext *context, SemaContext *temp_ temp_context->compilation_unit = context->compilation_unit; temp_context->call_env = context->call_env; temp_context->current_macro = context->current_macro; + temp_context->is_temp = true; return temp_context; } diff --git a/src/utils/lib.h b/src/utils/lib.h index b0c2e77d0..836de296a 100644 --- a/src/utils/lib.h +++ b/src/utils/lib.h @@ -343,7 +343,7 @@ static inline void* expand_(void *vec, size_t element_size) #define CONCAT(a, b) CONCAT_INNER(a, b) #define FOREACH(type__, name__, vec__) \ -type__* CONCAT(foreach_vec_, __LINE__) = (vec__); type__* CONCAT(foreach_vecend_, __LINE__) = CONCAT(foreach_vec_, __LINE__) + vec_size(CONCAT(foreach_vec_, __LINE__)); \ +type__* CONCAT(foreach_vec_, __LINE__) = (vec__); type__* CONCAT(foreach_vecend_, __LINE__) = CONCAT(foreach_vec_, __LINE__) ? CONCAT(foreach_vec_, __LINE__) + vec_size(CONCAT(foreach_vec_, __LINE__)) : NULL; \ type__* CONCAT(foreach_it_, __LINE__) = CONCAT(foreach_vec_, __LINE__); \ for (type__ name__ ; CONCAT(foreach_it_, __LINE__) < CONCAT(foreach_vecend_, __LINE__) ? (name__ = *CONCAT(foreach_it_, __LINE__), true) : false; CONCAT(foreach_it_, __LINE__)++)