------- Comment #6 from pault at gcc dot gnu dot org 2006-08-21 13:35 -------
Jakub and co.,
Does the below do it for you? Instead of passing null, I propose to pass the
address of a longlong containing zero. This then leaves the normal passing of
NULL to possibly represent a missing optional argument. It regtests OK.
I am proposing to pass a reference to a zero for unused arguments so that the
hidden, residual use of them in the master_entry does not cause an ICE.
Otherwise, it doesn't matter how the unused arguments are represented.
Paul
Index: gcc/fortran/trans-decl.c
===================================================================
*** gcc/fortran/trans-decl.c (revision 116268)
--- gcc/fortran/trans-decl.c (working copy)
*************** build_entry_thunks (gfc_namespace * ns)
*** 1561,1566 ****
--- 1561,1568 ----
tree args;
tree string_args;
tree tmp;
+ tree zero;
+ bool zero_flag;
locus old_loc;
/* This should always be a toplevel function. */
*************** build_entry_thunks (gfc_namespace * ns)
*** 1580,1585 ****
--- 1582,1590 ----
gfc_start_block (&body);
+ zero_flag = false;
+ zero = NULL_TREE;
+
/* Pass extra parameter identifying this entry point. */
tmp = build_int_cst (gfc_array_index_type, el->id);
args = tree_cons (NULL_TREE, tmp, NULL_TREE);
*************** build_entry_thunks (gfc_namespace * ns)
*** 1616,1621 ****
--- 1621,1627 ----
if (thunk_formal)
{
/* Pass the argument. */
+ /* TODO - missing optional arguments. */
DECL_ARTIFICIAL (thunk_formal->sym->backend_decl) = 1;
args = tree_cons (NULL_TREE, thunk_formal->sym->backend_decl,
args);
*************** build_entry_thunks (gfc_namespace * ns)
*** 1627,1634 ****
}
else
{
! /* Pass NULL for a missing argument. */
! args = tree_cons (NULL_TREE, null_pointer_node, args);
if (formal->sym->ts.type == BT_CHARACTER)
{
tmp = build_int_cst (gfc_charlen_type_node, 0);
--- 1633,1651 ----
}
else
{
! /* Pass the address of a long zero for any argument that
! is not used in this thunk. */
! if (!zero_flag)
! {
! tmp = build_int_cst (intQI_type_node, 0);
! zero = gfc_create_var (intQI_type_node, NULL);
! gfc_add_modify_expr (&body, zero, tmp);
! zero = fold_convert (pvoid_type_node,
! build_fold_addr_expr (zero));
! zero_flag = true;
! }
! args = tree_cons (NULL_TREE, zero, args);
!
if (formal->sym->ts.type == BT_CHARACTER)
{
tmp = build_int_cst (gfc_charlen_type_node, 0);
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25818