Fortran] PR92754 - fix an issue with resolving intrinsic functions
authorTobias Burnus <tobias@codesourcery.com>
Wed, 4 Dec 2019 12:19:55 +0000 (12:19 +0000)
committerTobias Burnus <burnus@gcc.gnu.org>
Wed, 4 Dec 2019 12:19:55 +0000 (13:19 +0100)
        gcc/fortran/
        PR fortran/92754
        * intrinsic.c (gfc_intrinsic_func_interface): Set
        sym's flavor, intrinsic and function attribute if
        unset.

        gcc/testsuite/
        PR fortran/92754
        gfortran.dg/intrinsic_9.f90: New.

From-SVN: r278961

gcc/fortran/ChangeLog
gcc/fortran/intrinsic.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/intrinsic_9.f90 [new file with mode: 0644]

index 3a188bac265b5acb9b0245207035d4727780c1ab..faac8fa02f5e08bbbace62a9dceea6ad28778cfd 100644 (file)
@@ -1,3 +1,10 @@
+2019-12-12  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/92754
+       * intrinsic.c (gfc_intrinsic_func_interface): Set
+       sym's flavor, intrinsic and function attribute if
+       unset.
+
 2019-12-04  Jakub Jelinek  <jakub@redhat.com>
 
        PR fortran/92756
index 572967f5d4ebe77443d0bef3058d85a83ee46075..76b53bb7117c2d97ee87a600af76354d7b360274 100644 (file)
@@ -4839,9 +4839,9 @@ gfc_check_intrinsic_standard (const gfc_intrinsic_sym* isym,
 match
 gfc_intrinsic_func_interface (gfc_expr *expr, int error_flag)
 {
+  gfc_symbol *sym;
   gfc_intrinsic_sym *isym, *specific;
   gfc_actual_arglist *actual;
-  const char *name;
   int flag;
 
   if (expr->value.function.isym != NULL)
@@ -4857,15 +4857,15 @@ gfc_intrinsic_func_interface (gfc_expr *expr, int error_flag)
       flag |= (actual->expr->ts.type != BT_INTEGER
               && actual->expr->ts.type != BT_CHARACTER);
 
-  name = expr->symtree->n.sym->name;
+  sym = expr->symtree->n.sym;
 
-  if (expr->symtree->n.sym->intmod_sym_id)
+  if (sym->intmod_sym_id)
     {
-      gfc_isym_id id = gfc_isym_id_by_intmod_sym (expr->symtree->n.sym);
+      gfc_isym_id id = gfc_isym_id_by_intmod_sym (sym);
       isym = specific = gfc_intrinsic_function_by_id (id);
     }
   else
-    isym = specific = gfc_find_function (name);
+    isym = specific = gfc_find_function (sym->name);
 
   if (isym == NULL)
     {
@@ -4879,7 +4879,7 @@ gfc_intrinsic_func_interface (gfc_expr *expr, int error_flag)
        || isym->id == GFC_ISYM_SNGL || isym->id == GFC_ISYM_DFLOAT)
       && gfc_init_expr_flag
       && !gfc_notify_std (GFC_STD_F2003, "Function %qs as initialization "
-                         "expression at %L", name, &expr->where))
+                         "expression at %L", sym->name, &expr->where))
     {
       if (!error_flag)
        gfc_pop_suppress_errors ();
@@ -4898,7 +4898,7 @@ gfc_intrinsic_func_interface (gfc_expr *expr, int error_flag)
          && id != GFC_ISYM_TRANSFER && id != GFC_ISYM_TRIM
          && !gfc_notify_std (GFC_STD_F2003, "Transformational function %qs "
                              "at %L is invalid in an initialization "
-                             "expression", name, &expr->where))
+                             "expression", sym->name, &expr->where))
        {
          if (!error_flag)
            gfc_pop_suppress_errors ();
@@ -4956,9 +4956,6 @@ gfc_intrinsic_func_interface (gfc_expr *expr, int error_flag)
 
 got_specific:
   expr->value.function.isym = specific;
-  if (!expr->symtree->n.sym->module)
-    gfc_intrinsic_symbol (expr->symtree->n.sym);
-
   if (!error_flag)
     gfc_pop_suppress_errors ();
 
@@ -4980,6 +4977,16 @@ got_specific:
                          "character arguments at %L", &expr->where))
     return MATCH_ERROR;
 
+  if (sym->attr.flavor == FL_UNKNOWN)
+    {
+      sym->attr.function = 1;
+      sym->attr.intrinsic = 1;
+      sym->attr.flavor = FL_PROCEDURE;
+    }
+
+  if (!sym->module)
+    gfc_intrinsic_symbol (sym);
+
   return MATCH_YES;
 }
 
index 1d6541a90972be2fd2f441f6addeb7ac2b8f6e69..e012bddef8c9fb04f1e47d586d65271b6ee9d142 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-12  Tobias Burnus  <tobias@codesourcery.com>
+
+       PR fortran/92754
+       gfortran.dg/intrinsic_9.f90: New.
+
 2019-12-04  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/92734
diff --git a/gcc/testsuite/gfortran.dg/intrinsic_9.f90 b/gcc/testsuite/gfortran.dg/intrinsic_9.f90
new file mode 100644 (file)
index 0000000..43959ad
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-do run }
+!
+! PR fortran/92754
+!
+! Contributed by G. Steinmetz
+!
+
+program p
+   integer :: max
+   block
+      character :: x = max('a','b')
+      !print *, x
+      if (x /= 'b') stop 1
+   end block
+end