This is the mail archive of the gcc-bugs@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]

[Bug fortran/47421] Wrong-code: Value of scalar ALLOCATABLE CHARACTER(len=n) dummy is mangled


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011.01.23 14:45:20
     Ever Confirmed|0                           |1

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-01-23 14:45:20 UTC ---
sub (character(kind=1)[1:.x] * & restrict x, integer(kind=4) & restrict n,
integer(kind=4) _x)
{
  try
    {
      *x = 0B;
  finally
   if (*x != 0B)
      __builtin_free ((void *) *x);

Ups! Why is the argument nullified? And freed at the end?


The issue seems to be related the following in gfc_get_symbol_decl:

      if (sym->ts.type == BT_CHARACTER)
        {
          if (TREE_CODE (length) == VAR_DECL
              && DECL_FILE_SCOPE_P (length))
            {
              gfc_defer_symbol_init (sym);

and thus to gfc_trans_deferred_vars's

      if (sym->attr.dimension)
      else if (sym->attr.allocatable

               || (sym->ts.type == BT_CLASS
                   && CLASS_DATA (sym)->attr.allocatable))
        {
          if (!sym->attr.save)
              /* Nullify and automatic deallocation of allocatable
                 scalars.  */

Draft patch:

diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 254db76..55d2f32 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -3304,7 +3304,7 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym,
gfc_wrapped_block * block)
          if (sym_has_alloc_comp && !seen_trans_deferred_array)
            gfc_trans_deferred_array (sym, block);
        }
-      else if (sym->attr.allocatable
+      else if ((sym->attr.allocatable && !sym->attr.dummy)
               || (sym->ts.type == BT_CLASS
                   && CLASS_DATA (sym)->attr.allocatable))
        {


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