This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gfortran] Fix NULL reference types.
- From: Paul Brook <paul at nowt dot org>
- To: fortran at gcc dot gnu dot org
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 18 Aug 2004 14:10:29 +0100
- Subject: [gfortran] Fix NULL reference types.
As part of his int_cst sharing work Nathan spotted that gfortran was creating
null pointers with REFERENCE_TYPE. Apparently the optimizers [could] assume
that a reference type argument is never NULL.
Patch below gives procedure arguments pointer type if they might be absent
(ie. NULL).
Tested on i686-linux.
Applied to mainline.
Paul
2004-08-18 Paul Brook <paul@codesourcery.com>
* trans-types.c (gfc_sym_type): Use pointer types for optional args.
Index: fortran/trans-types.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/fortran/trans-types.c,v
retrieving revision 1.9
diff -u -p -r1.9 trans-types.c
--- fortran/trans-types.c 17 Aug 2004 15:34:09 -0000 1.9
+++ fortran/trans-types.c 18 Aug 2004 11:36:40 -0000
@@ -972,7 +972,14 @@ gfc_sym_type (gfc_symbol * sym)
See f95_get_function_decl. For dummy function parameters return the
function type. */
if (byref)
- type = build_reference_type (type);
+ {
+ /* We must use pointer types for potentially absent variables. The
+ optimizers assume a reference type argument is never NULL. */
+ if (sym->attr.optional || sym->ns->proc_name->attr.entry_master)
+ type = build_pointer_type (type);
+ else
+ type = build_reference_type (type);
+ }
return (type);
}