@@ -512,6 +512,8 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr)
512512 {
513513 case GCC_JIT_FN_ATTRIBUTE_TARGET:
514514 return " target" ;
515+ case GCC_JIT_FN_ATTRIBUTE_USED:
516+ return " used" ;
515517 case GCC_JIT_FN_ATTRIBUTE_VISIBILITY:
516518 return " visibility" ;
517519 }
@@ -540,7 +542,8 @@ new_function (location *loc,
540542 int is_variadic,
541543 enum built_in_function builtin_id,
542544 int is_target_builtin,
543- const std::vector<std::pair<gcc_jit_fn_attribute, std::string>> &attributes)
545+ const std::vector<gcc_jit_fn_attribute> &attributes,
546+ const std::vector<std::pair<gcc_jit_fn_attribute, std::string>> &string_attributes)
544547{
545548 int i;
546549 param *param;
@@ -634,6 +637,21 @@ new_function (location *loc,
634637 }
635638
636639 for (auto attr: attributes)
640+ {
641+ tree ident = get_identifier (fn_attribute_to_string (attr));
642+
643+ /* See handle_used_attribute in gcc/c-family/c-attribs.cc. */
644+ if (attr == GCC_JIT_FN_ATTRIBUTE_USED)
645+ {
646+ TREE_USED (fndecl) = 1 ;
647+ DECL_PRESERVE_P (fndecl) = 1 ;
648+ }
649+
650+ DECL_ATTRIBUTES (fndecl) =
651+ tree_cons (ident, NULL_TREE, DECL_ATTRIBUTES (fndecl));
652+ }
653+
654+ for (auto attr: string_attributes)
637655 {
638656 gcc_jit_fn_attribute& name = std::get<0 >(attr);
639657 std::string& value = std::get<1 >(attr);
0 commit comments