]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: fix ICE overloading elemental intrinsics
authorHarald Anlauf <anlauf@gmx.de>
Thu, 13 Jan 2022 20:50:45 +0000 (21:50 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 14 Jan 2022 18:16:04 +0000 (19:16 +0100)
gcc/fortran/ChangeLog:

PR fortran/103782
* expr.c (gfc_simplify_expr): Adjust logic for when to scalarize a
call of an intrinsic which may have been overloaded.

gcc/testsuite/ChangeLog:

PR fortran/103782
* gfortran.dg/overload_4.f90: New test.

gcc/fortran/expr.c
gcc/testsuite/gfortran.dg/overload_4.f90 [new file with mode: 0644]

index a87686d821716984fd262f1af04dbdb270717150..20b88a8ef56c5eda8ab4af1143f117923c75fce8 100644 (file)
@@ -2219,10 +2219,9 @@ gfc_simplify_expr (gfc_expr *p, int type)
          && gfc_intrinsic_func_interface (p, 1) == MATCH_ERROR)
        return false;
 
-      if (p->expr_type == EXPR_FUNCTION)
+      if (p->symtree && (p->value.function.isym || p->ts.type == BT_UNKNOWN))
        {
-         if (p->symtree)
-           isym = gfc_find_function (p->symtree->n.sym->name);
+         isym = gfc_find_function (p->symtree->n.sym->name);
          if (isym && isym->elemental)
            scalarize_intrinsic_call (p, false);
        }
diff --git a/gcc/testsuite/gfortran.dg/overload_4.f90 b/gcc/testsuite/gfortran.dg/overload_4.f90
new file mode 100644 (file)
index 0000000..43207e3
--- /dev/null
@@ -0,0 +1,27 @@
+! { dg-do run }
+! { dg-additional-options "-Wno-intrinsic-shadow" }
+! PR fortran/103782 - ICE overloading an intrinsic like dble or real
+! Contributed by Urban Jost
+
+program runtest
+  implicit none
+  interface dble
+     procedure to_double
+  end interface dble
+  interface real
+     procedure floor ! not really FLOOR...
+  end interface real
+  if (any (dble ([10.0d0,20.0d0]) - [10.0d0,20.0d0] /= 0.d0)) stop 1
+  if (any (real ([1.5,2.5])       - [1.5,2.5]       /= 0.0 )) stop 2
+contains
+  elemental function to_double (valuein) result(d_out)
+    doubleprecision,intent(in) :: valuein
+    doubleprecision            :: d_out
+    d_out=valuein
+  end function to_double
+  elemental function floor (valuein) result(d_out) ! not really FLOOR...
+    real, intent(in) :: valuein
+    real             :: d_out
+    d_out=valuein
+  end function floor
+end program runtest