Bug 45748 - [4.5/4.6 Regression] -fimplicit-none failures when using intrinsic MAX
Summary: [4.5/4.6 Regression] -fimplicit-none failures when using intrinsic MAX
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.1
: P4 normal
Target Milestone: 4.5.2
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2010-09-22 16:13 UTC by Themos Tsikas
Modified: 2010-10-09 13:51 UTC (History)
2 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Known to work: 4.4.0
Known to fail: 4.5.0, 4.6.0
Last reconfirmed: 2010-09-22 20:22:16


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Themos Tsikas 2010-09-22 16:13:25 UTC
Code:
      SUBROUTINE BUG(WORK)
      DOUBLE PRECISION WORK(MAX(2,3))
      INTRINSIC        MAX
      END


Compile:
>gfortran  -fimplicit-none -c foo.f
foo.f:4.72:

      END
                                                                        1
Error: Symbol 'a1' at (1) has no IMPLICIT type
foo.f:4.72:

      END
                                                                        1
Error: Symbol 'a2' at (1) has no IMPLICIT type

________________________________________________________________

nonsensical error when there shouldn't be one?

Regards
Themos Tsikas
Comment 1 Jerry DeLisle 2010-09-22 19:09:19 UTC
Please post result of gfortran -v
Comment 2 Jerry DeLisle 2010-09-22 19:12:46 UTC
I do not see the problem with gfortran 4.3.4 on Cygwin
Comment 3 Dominique d'Humieres 2010-09-22 19:29:33 UTC
Confirmed on x86_64-apple-darwin10.3.0 for 4.5.0 and trunk, but not 4.4.4, hence it is a regression.
Comment 4 Tobias Burnus 2010-09-22 20:22:16 UTC
As you might have guessed, the error is with regards to the arguments of MAX which are A1 and A2.

The arguments are defined as BT_UNKNOWN, cf. in intrinsics.c:

  add_sym_1m ("max", GFC_ISYM_MAX, CLASS_ELEMENTAL, ACTUAL_NO,
              BT_UNKNOWN, 0, GFC_STD_F77,
              gfc_check_min_max, gfc_simplify_max, gfc_resolve_max,
              a1, BT_UNKNOWN, dr, REQUIRED, a2, BT_UNKNOWN, dr, REQUIRED);

The backtrace shows:

#0  gfc_set_default_type (sym=0x144e6b0, error_flag=1, ns=<value optimized out>)
    at fortran/symbol.c:263
#1  0x00000000005328d7 in resolve_formal_arglist (proc=0x144d1f0)
    at fortran/resolve.c:303
Comment 5 janus 2010-10-02 08:06:53 UTC
The following (pretty obvious) patch fixes it:

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 164899)
+++ gcc/fortran/resolve.c	(working copy)
@@ -297,11 +297,9 @@ resolve_formal_arglist (gfc_symbol *proc)
 	  continue;
 	}
 
-      if (sym->ts.type == BT_UNKNOWN)
-	{
-	  if (!sym->attr.function || sym->result == sym)
-	    gfc_set_default_type (sym, 1, sym->ns);
-	}
+      if (sym->ts.type == BT_UNKNOWN && !proc->attr.intrinsic
+	  && (!sym->attr.function || sym->result == sym))
+	gfc_set_default_type (sym, 1, sym->ns);
 
       gfc_resolve_array_spec (sym->as, 0);
Comment 6 janus 2010-10-02 10:38:45 UTC
Author: janus
Date: Sat Oct  2 10:38:42 2010
New Revision: 164901

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=164901
Log:
2010-10-02  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/45748
	* resolve.c (resolve_formal_arglist): Avoid setting default type for
	formal arguments of intrinsic procedures.

2010-10-02  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/45748
	* gfortran.dg/intrinsic_6.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/intrinsic_6.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 janus 2010-10-09 13:41:16 UTC
Author: janus
Date: Sat Oct  9 13:41:12 2010
New Revision: 165223

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

	PR fortran/45748
	* resolve.c (resolve_formal_arglist): Avoid setting default type for
	formal arguments of intrinsic procedures.


2010-10-09  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/45748
	* gfortran.dg/intrinsic_6.f90: New.

Added:
    branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/intrinsic_6.f90
Modified:
    branches/gcc-4_5-branch/gcc/fortran/ChangeLog
    branches/gcc-4_5-branch/gcc/fortran/resolve.c
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
Comment 8 janus 2010-10-09 13:51:11 UTC
Fixed on trunk and 4.5. Closing.