This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran] Fix PR 12841: Passing NULL to a subroutine



This needed two independent fixes:
1. when NULL appears in an arglist we don't want to compare shape and rank of the parameters
2. when building the function call EXPR_NULL does not need its address taken, because it already returns an address. Maybe it would be better to have it handled the same way as other pointers, but this seemed out of reach, as we use the backend's null_pointer_node.


Unfortunately, or number of total bugs is not lowered by this, because while investigating this bug, I ran into what is now PR15754.

- Tobi

Index: interface.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/interface.c,v
retrieving revision 1.4
diff -u -p -r1.4 interface.c
--- interface.c 27 May 2004 12:35:12 -0000      1.4
+++ interface.c 31 May 2004 22:37:18 -0000
@@ -1096,7 +1096,8 @@ compare_parameter (gfc_symbol * formal,
       return compare_interfaces (formal, actual->symtree->n.sym, 0);
     }

-  if (!gfc_compare_types (&formal->ts, &actual->ts))
+  if (actual->expr_type != EXPR_NULL
+      && !gfc_compare_types (&formal->ts, &actual->ts))
     return 0;

   if (symbol_rank (formal) == actual->rank)
@@ -1235,7 +1236,8 @@ compare_actual_formal (gfc_actual_arglis
          return 0;
        }

-      if (compare_pointer (f->sym, a->expr) == 0)
+      if (a->expr->expr_type != EXPR_NULL
+         && compare_pointer (f->sym, a->expr) == 0)
        {
          if (where)
            gfc_error ("Actual argument for '%s' must be a pointer at %L",
Index: trans-expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-expr.c,v
retrieving revision 1.7
diff -u -p -r1.7 trans-expr.c
--- trans-expr.c        30 May 2004 14:37:24 -0000      1.7
+++ trans-expr.c        31 May 2004 22:37:18 -0000
@@ -1099,10 +1099,12 @@ gfc_conv_function_call (gfc_se * se, gfc
          if (argss == gfc_ss_terminator)
             {
              gfc_conv_expr_reference (&parmse, arg->expr);
-              if (formal && formal->sym->attr.pointer)
+              if (formal && formal->sym->attr.pointer
+                 && arg->expr->expr_type != EXPR_NULL)
                 {
                   /* Scalar pointer dummy args require an extra level of
-                     indirection.  */
+                     indirection. The null pointer already contains
+                    this level of indirection. */
                   parmse.expr = gfc_build_addr_expr (NULL, parmse.expr);
                 }
             }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]