[Bug fortran/49023] ICE on invalid code with C_ASSOCIATED

burnus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed May 18 16:55:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49023

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-05-18 16:09:54 UTC ---
==31261== Invalid read of size 8
==31261==    at 0x510673: gfc_resolve_expr (resolve.c:2674)
==31261==    by 0x50E37C: resolve_code (resolve.c:9026)

That's at first "if" block gfc_iso_c_func_interface. In this example, one has
expr_type == EXPR_ARRAY. I think the following patch should be OK (for F2003,
in F2008, the pointer returned by functions also counts as variable).

Additionally, one needs to add a check for the second argument; the program
crashes for
  C_ASSOCIATED(x,[y])
at gfc_conv_array_constructor_expr, at fortran/trans-expr.c:4120

--- resolve.c   (revision 173865)
+++ resolve.c   (working copy)
@@ -2666,9 +2666,8 @@ gfc_iso_c_func_interface (gfc_symbol *sy
   gfc_typespec *arg_ts;
   symbol_attribute arg_attr;

-  if (args->expr->expr_type == EXPR_CONSTANT
-      || args->expr->expr_type == EXPR_OP
-      || args->expr->expr_type == EXPR_NULL)
+  if (args->expr->expr_type != EXPR_VARIABLE
+      || args->expr->symtree->n.sym->attr.flavor != FL_VARIABLE)
     {
       gfc_error ("Argument to '%s' at %L is not a variable",
                 sym->name, &(args->expr->where));



More information about the Gcc-bugs mailing list