@@ -539,6 +539,8 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr)
539539 return " const" ;
540540 case GCC_JIT_FN_ATTRIBUTE_WEAK:
541541 return " weak" ;
542+ case GCC_JIT_FN_ATTRIBUTE_NONNULL:
543+ return " nonnull" ;
542544 }
543545 return NULL ;
544546}
@@ -566,6 +568,7 @@ new_function (location *loc,
566568 enum built_in_function builtin_id,
567569 const std::vector<gcc_jit_fn_attribute> &attributes,
568570 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,
569572 int is_target_builtin)
570573{
571574 int i;
@@ -601,6 +604,8 @@ new_function (location *loc,
601604 DECL_RESULT (fndecl) = resdecl;
602605 DECL_CONTEXT (resdecl) = fndecl;
603606
607+ tree fn_attributes = NULL_TREE;
608+
604609 if (is_target_builtin)
605610 {
606611 tree *decl = target_builtins.get (name);
@@ -654,48 +659,24 @@ new_function (location *loc,
654659 DECL_DECLARED_INLINE_P (fndecl) = 1 ;
655660
656661 /* Add attribute "always_inline": */
657- DECL_ATTRIBUTES (fndecl) =
662+ fn_attributes =
658663 tree_cons (get_identifier (" always_inline" ),
659664 NULL ,
660- DECL_ATTRIBUTES (fndecl) );
665+ fn_attributes );
661666 }
662667
668+ /* All attributes need to be declared in `dummy-frontend.cc` and more
669+ specifically in `jit_attribute_table`. */
663670 for (auto attr: attributes)
664671 {
665- if (attr == GCC_JIT_FN_ATTRIBUTE_ALWAYS_INLINE)
666- {
672+ if (attr == GCC_JIT_FN_ATTRIBUTE_INLINE)
667673 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);
692674
693675 const char * attribute = fn_attribute_to_string (attr);
694676 if (attribute)
695677 {
696678 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);
699680 }
700681 }
701682
@@ -713,20 +694,33 @@ new_function (location *loc,
713694 if (!ident || !targetm.target_option .valid_attribute_p (fndecl, ident, attribute_value, 0 ))
714695 continue ;
715696
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)
718715 {
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);
723719 }
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);
728721 }
729722
723+ decl_attributes (&fndecl, fn_attributes, 0 );
730724 function *func = new function (this , fndecl, kind);
731725 m_functions.safe_push (func);
732726 return func;
@@ -2396,7 +2390,7 @@ add_try_catch (location *loc,
23962390 {
23972391 catch_body = build2 (CATCH_EXPR, void_type_node, NULL , catch_body);
23982392 tree try_catch = build2 (TRY_CATCH_EXPR, void_type_node,
2399- try_body, catch_body);
2393+ try_body, catch_body);
24002394 add_stmt (try_catch);
24012395 }
24022396}
@@ -3794,7 +3788,7 @@ void
37943788playback::context::
37953789init_types ()
37963790{
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
37983792 for reference. If TYPE_NAME is not set, debug info will not contain types */
37993793#define NAME_TYPE (t,n ) \
38003794if (t) \
0 commit comments