This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[lto] PATCH: add varargs support to DWARF reader
- From: Sandra Loosemore <sandra at codesourcery dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 20 Sep 2006 22:01:27 -0400
- Subject: [lto] PATCH: add varargs support to DWARF reader
This patch cleans up the reading of DWARF information for formal parameters and
makes it handle functions with varargs. OK to commit?
-Sandra
2006-09-20 Sandra Loosemore <sandra@codesourcery.com>
* gcc/lto/lto.c (lto_varargs_cookie): Define.
(lto_read_subroutine_type_subprogram_DIE): Robustify collection
of formal parameters and make it handle varargs.
(lto_read_unspecified_parameters_DIE): New.
(lto_read_DIE): Add lto_read_unspecified_parameters_DIE to table.
* gcc/lto/lto-tree.h (lto_varargs_cookie): Declare.
* gcc/lto/lto-lang.c (lto_init): Initialize lto_varargs_cookie.
Index: gcc/lto/lto.c
===================================================================
*** gcc/lto/lto.c (revision 117105)
--- gcc/lto/lto.c (working copy)
*************** struct DWARF2_CompUnit
*** 161,166 ****
--- 161,172 ----
unsigned char cu_pointer_size;
};
+ /* Variables */
+
+ /* Cookie for DWARF DW_TAG_unspecified_parameters. All we need is a uniquely
+ identifiable object; it doesn't need to carry any information. */
+ tree lto_varargs_cookie;
+
/* Forward Declarations */
static hashval_t
*************** lto_read_subroutine_type_subprogram_DIE
*** 1774,1781 ****
bool external;
VEC(tree,heap) *parms;
unsigned n_parms;
! unsigned i;
bool prototyped;
tree result;
int inlined = DW_INL_not_inlined;
--- 1780,1789 ----
bool external;
VEC(tree,heap) *parms;
unsigned n_parms;
! unsigned n_children;
! unsigned i, j;
bool prototyped;
+ bool varargs_p;
tree result;
int inlined = DW_INL_not_inlined;
*************** lto_read_subroutine_type_subprogram_DIE
*** 1857,1873 ****
sorry ("support for unprototyped functions not yet implemented");
parms = lto_collect_child_DIEs (fd, abbrev, context);
! n_parms = VEC_length (tree, parms);
! arg_types = make_tree_vec (n_parms + (prototyped ? 1 : 0));
! for (i = 0; i < n_parms; ++i)
{
tree parm = VEC_index (tree, parms, i);
! if (TREE_CODE (parm) != PARM_DECL)
! lto_file_corrupt_error ((lto_fd *)fd);
! TREE_VEC_ELT (arg_types, i) = TREE_TYPE (parm);
}
! if (prototyped)
! TREE_VEC_ELT (arg_types, n_parms) = void_type_node;
VEC_free (tree, heap, parms);
/* Build the function type. */
--- 1865,1899 ----
sorry ("support for unprototyped functions not yet implemented");
parms = lto_collect_child_DIEs (fd, abbrev, context);
!
! /* Per the DWARF spec, the children can include "other entries used
! by formal parameter entries, such as types", as well as parameters
! and a DW_TAG_unspecified_parameters to indicate varargs. So we need
! one loop over the children to count the number of actual parameters
! and another to assemble the parameter type vector. */
! n_children = VEC_length (tree, parms);
! n_parms = 0;
! varargs_p = !prototyped;
! for (i = 0; i < n_children; ++i)
{
tree parm = VEC_index (tree, parms, i);
! if (parm == lto_varargs_cookie)
! varargs_p = true;
! else if (TREE_CODE (parm) == PARM_DECL)
! n_parms++;
! }
! arg_types = make_tree_vec (n_parms + (varargs_p ? 0 : 1));
! for (i = 0, j = 0; i < n_children; ++i)
! {
! tree parm = VEC_index (tree, parms, i);
! if (TREE_CODE (parm) == PARM_DECL)
! {
! TREE_VEC_ELT (arg_types, j) = TREE_TYPE (parm);
! j++;
! }
}
! if (!varargs_p)
! TREE_VEC_ELT (arg_types, j) = void_type_node;
VEC_free (tree, heap, parms);
/* Build the function type. */
*************** lto_read_subroutine_type_subprogram_DIE
*** 1927,1932 ****
--- 1953,1972 ----
}
static tree
+ lto_read_unspecified_parameters_DIE (lto_info_fd *fd,
+ const DWARF2_abbrev *abbrev,
+ lto_context *context)
+ {
+ gcc_assert (abbrev->tag == DW_TAG_unspecified_parameters);
+ LTO_BEGIN_READ_ATTRS ()
+ {
+ }
+ LTO_END_READ_ATTRS ();
+ lto_read_child_DIEs (fd, abbrev, context);
+ return lto_varargs_cookie;
+ }
+
+ static tree
lto_read_pointer_type_DIE (lto_info_fd *fd,
const DWARF2_abbrev *abbrev,
lto_context *context)
*************** lto_read_DIE (lto_info_fd *fd, lto_conte
*** 2206,2212 ****
lto_read_subroutine_type_subprogram_DIE,
NULL, /* typedef */
NULL, /* union_type */
! NULL, /* unspecified_parameters */
NULL, /* variant */
NULL, /* common_block */
NULL, /* common_inclusion */
--- 2246,2252 ----
lto_read_subroutine_type_subprogram_DIE,
NULL, /* typedef */
NULL, /* union_type */
! lto_read_unspecified_parameters_DIE,
NULL, /* variant */
NULL, /* common_block */
NULL, /* common_inclusion */
Index: gcc/lto/lto-tree.h
===================================================================
*** gcc/lto/lto-tree.h (revision 117105)
--- gcc/lto/lto-tree.h (working copy)
*************** union lang_tree_node GTY(
*** 67,70 ****
--- 67,73 ----
/* Vector to keep track of external variables we've seen so far. */
extern GTY(()) VEC(tree,gc) *lto_global_var_decls;
+ /* Cookie for DWARF DW_TAG_unspecified_parameters. */
+ extern GTY(()) tree lto_varargs_cookie;
+
#endif /* GCC_LTO_TREE_H */
Index: gcc/lto/lto-lang.c
===================================================================
*** gcc/lto/lto-lang.c (revision 117105)
--- gcc/lto/lto-lang.c (working copy)
*************** lto_init (void)
*** 161,166 ****
--- 161,167 ----
/* Initialize LTO-specific data structures. */
lto_global_var_decls = VEC_alloc (tree, gc, 256);
+ lto_varargs_cookie = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE);
return true;
}