Skip to content

Commit eba45e4

Browse files
committed
fixup! WIP: Add support for function attributes
Implement weak and alias function attributes
1 parent 9d5b6b2 commit eba45e4

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

gcc/jit/jit-playback.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr)
515515
{
516516
switch (attr)
517517
{
518+
case GCC_JIT_FN_ATTRIBUTE_ALIAS:
519+
return "alias";
518520
case GCC_JIT_FN_ATTRIBUTE_ALWAYS_INLINE:
519521
return "always_inline";
520522
case GCC_JIT_FN_ATTRIBUTE_INLINE:
@@ -535,6 +537,8 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr)
535537
return "pure";
536538
case GCC_JIT_FN_ATTRIBUTE_CONST:
537539
return "const";
540+
case GCC_JIT_FN_ATTRIBUTE_WEAK:
541+
return "weak";
538542
}
539543
return NULL;
540544
}
@@ -682,6 +686,9 @@ new_function (location *loc,
682686
/* See handle_const_attribute in gcc/c-family/c-attribs.cc. */
683687
else if (attr == GCC_JIT_FN_ATTRIBUTE_CONST)
684688
TREE_READONLY (fndecl) = 1;
689+
/* See handle_weak_attribute in gcc/c-family/c-attribs.cc. */
690+
else if (attr == GCC_JIT_FN_ATTRIBUTE_WEAK)
691+
declare_weak (fndecl);
685692

686693
const char* attribute = fn_attribute_to_string (attr);
687694
if (attribute)
@@ -706,6 +713,15 @@ new_function (location *loc,
706713
if (!ident || !targetm.target_option.valid_attribute_p (fndecl, ident, attribute_value, 0))
707714
continue;
708715

716+
/* See handle_alias_ifunc_attribute in gcc/c-family/c-attribs.cc. */
717+
if (name == GCC_JIT_FN_ATTRIBUTE_ALIAS)
718+
{
719+
tree id = get_identifier (value.c_str ());
720+
/* This counts as a use of the object pointed to. */
721+
TREE_USED (id) = 1;
722+
DECL_INITIAL (fndecl) = error_mark_node;
723+
}
724+
709725
if (ident)
710726
DECL_ATTRIBUTES (fndecl) =
711727
tree_cons (ident, attribute_value, DECL_ATTRIBUTES (fndecl));
@@ -2282,6 +2298,9 @@ postprocess ()
22822298

22832299
current_function_decl = NULL;
22842300
}
2301+
else
2302+
/* Add to cgraph to output aliases: */
2303+
rest_of_decl_compilation (m_inner_fndecl, true, 0);
22852304
}
22862305

22872306
/* Don't leak vec's internal buffer (in non-GC heap) when we are

gcc/jit/libgccjit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,7 @@ gcc_jit_type_set_packed (gcc_jit_type *type);
20972097
/* Function attributes. */
20982098
enum gcc_jit_fn_attribute
20992099
{
2100+
GCC_JIT_FN_ATTRIBUTE_ALIAS,
21002101
GCC_JIT_FN_ATTRIBUTE_ALWAYS_INLINE,
21012102
GCC_JIT_FN_ATTRIBUTE_INLINE,
21022103
GCC_JIT_FN_ATTRIBUTE_NOINLINE,
@@ -2107,6 +2108,7 @@ enum gcc_jit_fn_attribute
21072108
GCC_JIT_FN_ATTRIBUTE_RETURNS_TWICE,
21082109
GCC_JIT_FN_ATTRIBUTE_PURE,
21092110
GCC_JIT_FN_ATTRIBUTE_CONST,
2111+
GCC_JIT_FN_ATTRIBUTE_WEAK,
21102112
};
21112113

21122114
/* Add an attribute to a function. */

0 commit comments

Comments
 (0)