Bug 50379 - ICE in gfc_typenode_for_spec at fortran/trans-types.c
Summary: ICE in gfc_typenode_for_spec at fortran/trans-types.c
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.1
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2011-09-13 09:04 UTC by Vittorio Zecca
Modified: 2011-09-13 18:39 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-09-13 00:00:00


Attachments
just compile it (144 bytes, text/plain)
2011-09-13 09:04 UTC, Vittorio Zecca
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vittorio Zecca 2011-09-13 09:04:50 UTC
Created attachment 25258 [details]
just compile it

ICE in gfc_typenode_for_spec at fortran/trans-types.c
Comment 1 Tobias Burnus 2011-09-13 09:12:31 UTC
With GCC 4.3::

      interface res
                   1
Error: VARIABLE attribute of 'res' conflicts with PROCEDURE attribute at (1)

Having a generic name which is the same as the result variable looks wrong ...


I think gfortran stopped rejecting the code in decl.c/symbol.c since 4.4 when procedure-pointer (results) were allowed - such as in the following valid example:

      function f() result(res)
        interface
          subroutine res
          end subroutine
        end interface
        pointer :: res
        res => null()
      end
Comment 2 janus 2011-09-13 10:39:40 UTC
Note: We get the correct error message (twice, unfortunately) for:

  function f() result(res)
    interface res
      subroutine sub
      end subroutine
    end interface
  end 


  function f() result(res)
                          1
Error: PROCEDURE attribute conflicts with RESULT attribute in 'res' at (1)



but not when the interface is empty:

    interface res
    end interface
Comment 3 janus 2011-09-13 13:08:53 UTC
One way to reject it would be:


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c       (revision 178778)
+++ gcc/fortran/resolve.c       (working copy)
@@ -10567,6 +10567,12 @@
                     "in '%s' at %L", sym->name, &sym->declared_at);
          return FAILURE;
        }
+      if (sym->attr.generic && sym->attr.result)
+       {
+         gfc_error ("GENERIC attribute conflicts with RESULT attribute "
+                    "in '%s' at %L", sym->name, &sym->declared_at);
+         return FAILURE;
+       }
       if (sym->attr.external && sym->attr.function
          && ((sym->attr.if_source == IFSRC_DECL && !sym->attr.procedure)
              || sym->attr.contained))
Comment 4 janus 2011-09-13 14:02:53 UTC
Or better:


Index: gcc/fortran/symbol.c
===================================================================
--- gcc/fortran/symbol.c	(revision 178778)
+++ gcc/fortran/symbol.c	(working copy)
@@ -373,7 +373,7 @@ check_conflict (symbol_attribute *attr, const char
     *volatile_ = "VOLATILE", *is_protected = "PROTECTED",
     *is_bind_c = "BIND(C)", *procedure = "PROCEDURE",
     *asynchronous = "ASYNCHRONOUS", *codimension = "CODIMENSION",
-    *contiguous = "CONTIGUOUS";
+    *contiguous = "CONTIGUOUS", *generic = "GENERIC";
   static const char *threadprivate = "THREADPRIVATE";
 
   const char *a1, *a2;
@@ -490,8 +490,6 @@ check_conflict (symbol_attribute *attr, const char
   conf (in_common, codimension);
   conf (in_common, result);
 
-  conf (dummy, result);
-
   conf (in_equivalence, use_assoc);
   conf (in_equivalence, codimension);
   conf (in_equivalence, dummy);
@@ -503,7 +501,9 @@ check_conflict (symbol_attribute *attr, const char
   conf (in_equivalence, allocatable);
   conf (in_equivalence, threadprivate);
 
+  conf (dummy, result);
   conf (entry, result);
+  conf (generic, result);
 
   conf (function, subroutine);
Comment 5 janus 2011-09-13 18:19:18 UTC
The patch in comment #4 regtests cleanly. Will commit as obvious.
Comment 6 janus 2011-09-13 18:37:41 UTC
Author: janus
Date: Tue Sep 13 18:37:33 2011
New Revision: 178829

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178829
Log:
2011-09-13  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50379
	* symbol.c (check_conflict): Check conflict between GENERIC and RESULT
	attributes.


2011-09-13  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/50379
	* gfortran.dg/result_2.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/result_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 janus 2011-09-13 18:39:33 UTC
Fixed on trunk with r178829. Closing.

Thanks for the report!