@links on macros would not be added to calling functions.

This commit is contained in:
Christoffer Lerno
2025-07-17 15:17:58 +02:00
parent ee35001732
commit 774a375ce7
3 changed files with 26 additions and 1 deletions

View File

@@ -57,6 +57,7 @@
- Fix stringify of $vaexpr #2301.
- Segfault when failing to cast subexpression to 'isz' in pointer subtraction #2305.
- Fix unexpected display of macro definition when passing a poisoned expression #2305.
- `@links` on macros would not be added to calling functions.
### Stdlib changes
- Improve contract for readline. #2280

View File

@@ -862,13 +862,17 @@ static ResolvedAttrData *copy_attrs_resolved(CopyStruct *c, ResolvedAttrData *da
{
if (!data) return NULL;
ResolvedAttrData *copy = MALLOCS(ResolvedAttrData);
const char **new_links = NULL;
FOREACH(const char *, link, data->links) vec_add(new_links, link);
*copy = (ResolvedAttrData) {
.tags = copy_attributes(c, data->tags),
.deprecated = data->deprecated,
.links = data->links,
.links = new_links,
.section = data->section,
.wasm_module = data->wasm_module
};
const char **new = NULL;
return copy;
}

View File

@@ -2550,6 +2550,26 @@ bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *s
bool call_var_optional, bool *no_match_ref)
{
bool is_always_const = decl->func_decl.signature.attrs.always_const;
if (decl->resolved_attributes && decl->attrs_resolved && decl->attrs_resolved->links)
{
Decl *func = context->call_env.current_function;
if (!func)
{
RETURN_SEMA_ERROR(call_expr, "Cannot call macro with '@links' outside of a function.");
}
assert(func->resolved_attributes);
if (!func->attrs_resolved)
{
func->attrs_resolved = MALLOCS(ResolvedAttrData);
*func->attrs_resolved = (ResolvedAttrData) { .overload = INVALID_SPAN };
}
const char **updated = func->attrs_resolved->links;
FOREACH(const char *, link, decl->attrs_resolved->links)
{
vec_add(updated, link);
}
func->attrs_resolved->links = updated;
}
bool is_outer = call_expr->call_expr.is_outer_call;
ASSERT_SPAN(call_expr, decl->decl_kind == DECL_MACRO);