diff --git a/lib/std/math/math.c3 b/lib/std/math/math.c3 index ffe1d816a..21a703133 100644 --- a/lib/std/math/math.c3 +++ b/lib/std/math/math.c3 @@ -377,7 +377,7 @@ macro tan(x) $elif ($Type.typeid == float.typeid): return _tanf(x); $else: - return tan(x); + return _tan(x); $endif; } @@ -691,5 +691,5 @@ extern fn double _atan2(double, double) @extern("atan2"); extern fn float _atan2f(float, float) @extern("atan2f"); extern fn void _sincos(double, double*) @extern("sincos"); extern fn void _sincosf(float, float*) @extern("sincosf"); -extern fn void _tan(double x, double y) @extern("tan"); -extern fn void _tanf(double x, double y) @extern("tanf"); \ No newline at end of file +extern fn double _tan(double x) @extern("tan"); +extern fn float _tanf(float x) @extern("tanf"); \ No newline at end of file diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 1847904e7..9842fae17 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -1645,6 +1645,7 @@ typedef struct SemaContext_ CallEnv call_env; Decl *current_macro; ScopeId scope_id; + unsigned macro_call_depth; Ast *break_target; AstId break_defer; Ast *continue_target; diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 92320c78a..8e7c6c729 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1635,7 +1635,11 @@ static inline bool sema_expr_analyse_func_call(SemaContext *context, Expr *expr, bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *struct_var, Decl *decl, bool optional) { assert(decl->decl_kind == DECL_MACRO); - + if (context->macro_call_depth > 1024) + { + SEMA_ERROR(call_expr, "Failure evaluating macro, max call depth reached."); + return false; + } copy_begin(); Decl **params = copy_decl_list_macro(decl->func_decl.signature.params); Ast *body = copy_ast_macro(astptr(decl->func_decl.body)); @@ -1731,6 +1735,7 @@ bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *s Type *rtype = NULL; sema_context_init(¯o_context, decl->unit); macro_context.compilation_unit = context->unit; + macro_context.macro_call_depth = context->macro_call_depth + 1; macro_context.call_env = context->call_env; rtype = decl->func_decl.signature.rtype ? type_infoptr(decl->func_decl.signature.rtype)->type : NULL; macro_context.expected_block_type = rtype; diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index 1bf8cb4bc..ccb45e459 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -2792,6 +2792,7 @@ bool sema_analyse_function_body(SemaContext *context, Decl *func) .pure = func->func_decl.signature.attrs.is_pure }; context->rtype = prototype->rtype; + context->macro_call_depth = 0; context->active_scope = (DynamicScope) { .scope_id = 0, .depth = 0, diff --git a/src/version.h b/src/version.h index 942cd4fd2..c33a2abe6 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.44" \ No newline at end of file +#define COMPILER_VERSION "0.4.45" \ No newline at end of file