From eba45e495e6801967e9ffe4575e9589c5faef74f Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Thu, 27 Jul 2023 11:25:51 -0400 Subject: [PATCH] fixup! WIP: Add support for function attributes Implement weak and alias function attributes --- gcc/jit/jit-playback.cc | 19 +++++++++++++++++++ gcc/jit/libgccjit.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc index 88e1b21203020..fcc274213de52 100644 --- a/gcc/jit/jit-playback.cc +++ b/gcc/jit/jit-playback.cc @@ -515,6 +515,8 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr) { switch (attr) { + case GCC_JIT_FN_ATTRIBUTE_ALIAS: + return "alias"; case GCC_JIT_FN_ATTRIBUTE_ALWAYS_INLINE: return "always_inline"; case GCC_JIT_FN_ATTRIBUTE_INLINE: @@ -535,6 +537,8 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr) return "pure"; case GCC_JIT_FN_ATTRIBUTE_CONST: return "const"; + case GCC_JIT_FN_ATTRIBUTE_WEAK: + return "weak"; } return NULL; } @@ -682,6 +686,9 @@ new_function (location *loc, /* See handle_const_attribute in gcc/c-family/c-attribs.cc. */ else if (attr == GCC_JIT_FN_ATTRIBUTE_CONST) TREE_READONLY (fndecl) = 1; + /* See handle_weak_attribute in gcc/c-family/c-attribs.cc. */ + else if (attr == GCC_JIT_FN_ATTRIBUTE_WEAK) + declare_weak (fndecl); const char* attribute = fn_attribute_to_string (attr); if (attribute) @@ -706,6 +713,15 @@ new_function (location *loc, if (!ident || !targetm.target_option.valid_attribute_p (fndecl, ident, attribute_value, 0)) continue; + /* See handle_alias_ifunc_attribute in gcc/c-family/c-attribs.cc. */ + if (name == GCC_JIT_FN_ATTRIBUTE_ALIAS) + { + tree id = get_identifier (value.c_str ()); + /* This counts as a use of the object pointed to. */ + TREE_USED (id) = 1; + DECL_INITIAL (fndecl) = error_mark_node; + } + if (ident) DECL_ATTRIBUTES (fndecl) = tree_cons (ident, attribute_value, DECL_ATTRIBUTES (fndecl)); @@ -2282,6 +2298,9 @@ postprocess () current_function_decl = NULL; } + else + /* Add to cgraph to output aliases: */ + rest_of_decl_compilation (m_inner_fndecl, true, 0); } /* Don't leak vec's internal buffer (in non-GC heap) when we are diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index 60eaf39bff6ea..10a2a21017d5c 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -2097,6 +2097,7 @@ gcc_jit_type_set_packed (gcc_jit_type *type); /* Function attributes. */ enum gcc_jit_fn_attribute { + GCC_JIT_FN_ATTRIBUTE_ALIAS, GCC_JIT_FN_ATTRIBUTE_ALWAYS_INLINE, GCC_JIT_FN_ATTRIBUTE_INLINE, GCC_JIT_FN_ATTRIBUTE_NOINLINE, @@ -2107,6 +2108,7 @@ enum gcc_jit_fn_attribute GCC_JIT_FN_ATTRIBUTE_RETURNS_TWICE, GCC_JIT_FN_ATTRIBUTE_PURE, GCC_JIT_FN_ATTRIBUTE_CONST, + GCC_JIT_FN_ATTRIBUTE_WEAK, }; /* Add an attribute to a function. */