@@ -539,6 +539,8 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr)
539
539
return " const" ;
540
540
case GCC_JIT_FN_ATTRIBUTE_WEAK:
541
541
return " weak" ;
542
+ case GCC_JIT_FN_ATTRIBUTE_NONNULL:
543
+ return " nonnull" ;
542
544
}
543
545
return NULL ;
544
546
}
@@ -566,6 +568,7 @@ new_function (location *loc,
566
568
enum built_in_function builtin_id,
567
569
const std::vector<gcc_jit_fn_attribute> &attributes,
568
570
const std::vector<std::pair<gcc_jit_fn_attribute, std::string>> &string_attributes,
571
+ const std::vector<std::pair<gcc_jit_fn_attribute, std::vector<int >>> &int_array_attributes,
569
572
int is_target_builtin)
570
573
{
571
574
int i;
@@ -601,6 +604,8 @@ new_function (location *loc,
601
604
DECL_RESULT (fndecl) = resdecl;
602
605
DECL_CONTEXT (resdecl) = fndecl;
603
606
607
+ tree fn_attributes = NULL_TREE;
608
+
604
609
if (is_target_builtin)
605
610
{
606
611
tree *decl = target_builtins.get (name);
@@ -654,48 +659,24 @@ new_function (location *loc,
654
659
DECL_DECLARED_INLINE_P (fndecl) = 1 ;
655
660
656
661
/* Add attribute "always_inline": */
657
- DECL_ATTRIBUTES (fndecl) =
662
+ fn_attributes =
658
663
tree_cons (get_identifier (" always_inline" ),
659
664
NULL ,
660
- DECL_ATTRIBUTES (fndecl) );
665
+ fn_attributes );
661
666
}
662
667
668
+ /* All attributes need to be declared in `dummy-frontend.cc` and more
669
+ specifically in `jit_attribute_table`. */
663
670
for (auto attr: attributes)
664
671
{
665
- if (attr == GCC_JIT_FN_ATTRIBUTE_ALWAYS_INLINE)
666
- {
672
+ if (attr == GCC_JIT_FN_ATTRIBUTE_INLINE)
667
673
DECL_DECLARED_INLINE_P (fndecl) = 1 ;
668
- DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1 ;
669
- }
670
- else if (attr == GCC_JIT_FN_ATTRIBUTE_INLINE)
671
- DECL_DECLARED_INLINE_P (fndecl) = 1 ;
672
- else if (attr == GCC_JIT_FN_ATTRIBUTE_NOINLINE)
673
- DECL_UNINLINABLE (fndecl) = 1 ;
674
- /* See handle_used_attribute in gcc/c-family/c-attribs.cc. */
675
- else if (attr == GCC_JIT_FN_ATTRIBUTE_USED)
676
- {
677
- TREE_USED (fndecl) = 1 ;
678
- DECL_PRESERVE_P (fndecl) = 1 ;
679
- }
680
- /* See handle_returns_twice_attribute in gcc/c-family/c-attribs.cc. */
681
- else if (attr == GCC_JIT_FN_ATTRIBUTE_RETURNS_TWICE)
682
- DECL_IS_RETURNS_TWICE (fndecl) = 1 ;
683
- /* See handle_pure_attribute in gcc/c-family/c-attribs.cc. */
684
- else if (attr == GCC_JIT_FN_ATTRIBUTE_PURE)
685
- DECL_PURE_P (fndecl) = 1 ;
686
- /* See handle_const_attribute in gcc/c-family/c-attribs.cc. */
687
- else if (attr == GCC_JIT_FN_ATTRIBUTE_CONST)
688
- 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);
692
674
693
675
const char * attribute = fn_attribute_to_string (attr);
694
676
if (attribute)
695
677
{
696
678
tree ident = get_identifier (attribute);
697
- DECL_ATTRIBUTES (fndecl) =
698
- tree_cons (ident, NULL_TREE, DECL_ATTRIBUTES (fndecl));
679
+ fn_attributes = tree_cons (ident, NULL_TREE, fn_attributes);
699
680
}
700
681
}
701
682
@@ -713,20 +694,33 @@ new_function (location *loc,
713
694
if (!ident || !targetm.target_option .valid_attribute_p (fndecl, ident, attribute_value, 0 ))
714
695
continue ;
715
696
716
- /* See handle_alias_ifunc_attribute in gcc/c-family/c-attribs.cc. */
717
- if (name == GCC_JIT_FN_ATTRIBUTE_ALIAS)
697
+ if (ident)
698
+ fn_attributes = tree_cons (ident, attribute_value, fn_attributes);
699
+ }
700
+
701
+ for (auto attr: int_array_attributes)
702
+ {
703
+ gcc_jit_fn_attribute& name = std::get<0 >(attr);
704
+ std::vector<int >& values = std::get<1 >(attr);
705
+
706
+ const char * attribute = fn_attribute_to_string (name);
707
+ tree ident = attribute ? get_identifier (attribute) : NULL ;
708
+
709
+ if (!ident)
710
+ continue ;
711
+
712
+ tree tree_list = NULL_TREE;
713
+ tree *p_tree_list = &tree_list;
714
+ for (auto value : values)
718
715
{
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;
716
+ tree int_value = build_int_cst (integer_type_node, value);
717
+ *p_tree_list = build_tree_list (NULL , int_value);
718
+ p_tree_list = &TREE_CHAIN (*p_tree_list);
723
719
}
724
-
725
- if (ident)
726
- DECL_ATTRIBUTES (fndecl) =
727
- tree_cons (ident, attribute_value, DECL_ATTRIBUTES (fndecl));
720
+ fn_attributes = tree_cons (ident, tree_list, fn_attributes);
728
721
}
729
722
723
+ decl_attributes (&fndecl, fn_attributes, 0 );
730
724
function *func = new function (this , fndecl, kind);
731
725
m_functions.safe_push (func);
732
726
return func;
@@ -2396,7 +2390,7 @@ add_try_catch (location *loc,
2396
2390
{
2397
2391
catch_body = build2 (CATCH_EXPR, void_type_node, NULL , catch_body);
2398
2392
tree try_catch = build2 (TRY_CATCH_EXPR, void_type_node,
2399
- try_body, catch_body);
2393
+ try_body, catch_body);
2400
2394
add_stmt (try_catch);
2401
2395
}
2402
2396
}
@@ -3794,7 +3788,7 @@ void
3794
3788
playback::context::
3795
3789
init_types ()
3796
3790
{
3797
- /* See lto_init() in lto-lang.cc or void visit (TypeBasic *t) in D's types.cc
3791
+ /* See lto_init() in lto-lang.cc or void visit (TypeBasic *t) in D's types.cc
3798
3792
for reference. If TYPE_NAME is not set, debug info will not contain types */
3799
3793
#define NAME_TYPE (t,n ) \
3800
3794
if (t) \
0 commit comments