@@ -512,6 +512,8 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr)
512
512
{
513
513
case GCC_JIT_FN_ATTRIBUTE_TARGET:
514
514
return " target" ;
515
+ case GCC_JIT_FN_ATTRIBUTE_USED:
516
+ return " used" ;
515
517
case GCC_JIT_FN_ATTRIBUTE_VISIBILITY:
516
518
return " visibility" ;
517
519
}
@@ -540,7 +542,8 @@ new_function (location *loc,
540
542
int is_variadic,
541
543
enum built_in_function builtin_id,
542
544
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)
544
547
{
545
548
int i;
546
549
param *param;
@@ -634,6 +637,21 @@ new_function (location *loc,
634
637
}
635
638
636
639
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)
637
655
{
638
656
gcc_jit_fn_attribute& name = std::get<0 >(attr);
639
657
std::string& value = std::get<1 >(attr);
0 commit comments