@@ -467,7 +467,19 @@ new_compound_type (location *loc,
467467
468468 if (is_packed)
469469 TYPE_PACKED (t) = 1 ;
470- if (is_addressable) TREE_ADDRESSABLE (t) = 1 ;
470+
471+ // gcc_assert (!is_addressable);
472+ if (is_addressable)
473+ {
474+ TREE_ADDRESSABLE (t) = 1 ;
475+ /* if (TREE_CODE (t) == COMPOUND_LITERAL_EXPR)
476+ {
477+ fprintf (stderr, "Is compound literal\n");
478+ TREE_ADDRESSABLE (COMPOUND_LITERAL_EXPR_DECL (t)) = 1;
479+ }
480+ else
481+ fprintf (stderr, "Is NOT compound literal\n");*/
482+ }
471483 if (loc)
472484 set_tree_location (t, loc);
473485
@@ -653,24 +665,32 @@ new_function (location *loc,
653665 const std::vector<std::pair<gcc_jit_fn_attribute,
654666 std::vector<int >>>
655667 &int_array_attributes,
656- bool is_target_builtin)
668+ bool is_target_builtin,
669+ bool is_indirect_return)
657670{
658671 int i;
659672 param *param;
660673
661674 // can return_type be NULL?
662675 gcc_assert (name);
663676
677+ tree func_return_type = return_type->as_tree ();
678+ if (is_indirect_return)
679+ {
680+ func_return_type = build_variant_type_copy (func_return_type);
681+ TREE_ADDRESSABLE (func_return_type) = 1 ;
682+ }
683+
664684 tree *arg_types = (tree *)xcalloc (params->length (), sizeof (tree*));
665685 FOR_EACH_VEC_ELT (*params, i, param)
666686 arg_types[i] = TREE_TYPE (param->as_tree ());
667687
668688 tree fn_type;
669689 if (is_variadic)
670- fn_type = build_varargs_function_type_array (return_type-> as_tree () ,
690+ fn_type = build_varargs_function_type_array (func_return_type ,
671691 params->length (), arg_types);
672692 else
673- fn_type = build_function_type_array (return_type-> as_tree () ,
693+ fn_type = build_function_type_array (func_return_type ,
674694 params->length (), arg_types);
675695 free (arg_types);
676696
@@ -682,7 +702,7 @@ new_function (location *loc,
682702 set_tree_location (fndecl, loc);
683703
684704 tree resdecl = build_decl (UNKNOWN_LOCATION, RESULT_DECL,
685- NULL_TREE, return_type-> as_tree () );
705+ NULL_TREE, func_return_type );
686706 DECL_ARTIFICIAL (resdecl) = 1 ;
687707 DECL_IGNORED_P (resdecl) = 1 ;
688708 DECL_RESULT (fndecl) = resdecl;
@@ -1593,7 +1613,17 @@ build_call (location *loc,
15931613 vec<tree, va_gc> *tree_args;
15941614 vec_alloc (tree_args, args->length ());
15951615 for (unsigned i = 0 ; i < args->length (); i++)
1616+ {
1617+ if (TREE_ADDRESSABLE (TREE_TYPE ((*args)[i]->as_tree ())))
1618+ {
1619+ fprintf (stderr, " Function:\n " );
1620+ debug_tree (fn_ptr);
1621+ fprintf (stderr, " Argument:\n " );
1622+ debug_tree ((*args)[i]->as_tree ());
1623+ abort ();
1624+ }
15961625 tree_args->quick_push ((*args)[i]->as_tree ());
1626+ }
15971627
15981628 if (loc)
15991629 set_tree_location (fn_ptr, loc);
@@ -1604,6 +1634,11 @@ build_call (location *loc,
16041634
16051635 tree call = build_call_vec (return_type,
16061636 fn_ptr, tree_args);
1637+ if (TREE_ADDRESSABLE (return_type))
1638+ {
1639+ CALL_EXPR_RETURN_SLOT_OPT (call) = true ;
1640+ // fprintf (stderr, "Setting return slot opt\n");
1641+ }
16071642
16081643 if (require_tail_call)
16091644 CALL_EXPR_MUST_TAIL_CALL (call) = 1 ;
@@ -2052,6 +2087,18 @@ get_aligned (size_t alignment_in_bytes) const
20522087 return new type (t_new_type);
20532088}
20542089
2090+ /* Construct a playback::type instance (wrapping a tree)
2091+ with TREE_ADDRESSABLE set. */
2092+
2093+ playback::type *
2094+ playback::type::
2095+ get_addressable () const
2096+ {
2097+ tree t_new_type = build_variant_type_copy (m_inner);
2098+ TREE_ADDRESSABLE (t_new_type) = 1 ;
2099+ return new type (t_new_type);
2100+ }
2101+
20552102/* Construct a playback::type instance (wrapping a tree)
20562103 for the given vector type. */
20572104
@@ -2120,6 +2167,8 @@ dereference (location *loc)
21202167{
21212168 tree ptr = as_tree ();
21222169 tree datum = get_context ()->new_dereference (ptr, loc);
2170+ /* fprintf (stderr, "ptr: %p\n", ptr);
2171+ fprintf (stderr, "deref: %p\n", datum);*/
21232172 return new lvalue (get_context (), datum);
21242173}
21252174
@@ -2294,12 +2343,13 @@ new_local (location *loc,
22942343 type->as_tree ());
22952344 else
22962345 {
2297- inner = build_decl (UNKNOWN_LOCATION, VAR_DECL,
2346+ inner = create_tmp_var (type->as_tree (), " JITTMP" );
2347+ /* inner = build_decl (UNKNOWN_LOCATION, VAR_DECL,
22982348 create_tmp_var_name ("JITTMP"),
22992349 type->as_tree ());
23002350 DECL_ARTIFICIAL (inner) = 1;
23012351 DECL_IGNORED_P (inner) = 1;
2302- DECL_NAMELESS (inner) = 1 ;
2352+ DECL_NAMELESS (inner) = 1;*/
23032353 }
23042354 DECL_CONTEXT (inner) = this ->m_inner_fndecl ;
23052355
0 commit comments