Re: [Patch] PR fortran/100154 - [9/10/11/12 Regression] ICE in gfc_conv_procedure_call, at fortran/trans-expr.c:6131

2021-04-24 Thread Paul Richard Thomas via Gcc-patches
Hi Harald,

It looks good to me! Keep clear of 11-branch until release but OK for the
others.

Thanks

Paul


On Fri, 23 Apr 2021 at 00:18, Harald Anlauf via Fortran 
wrote:

> Now with the correct patch attached ...
>
> Sorry for the confusion!
>
> ---
>
> Dear Fortranners,
>
> we need to check the arguments to the affected GNU intrinsic extensions
> properly, and - as pointed out in the PR by Tobias - we need to allow
> function references that have a data pointer result.  Also the argument
> names of the character arguments of the subroutine versions needed a
> fix ("c" instead of "count").
>
> Regtested on x86_64-pc-linux-gnu.  OK for mainline (12)?
> OK for backports after 11.1 release?
>
> Thanks,
> Harald
>
>
> PR fortran/100154 - ICE in gfc_conv_procedure_call, at
> fortran/trans-expr.c:6131
>
> Add appropriate static checks for the character and status arguments to
> the GNU Fortran intrinsic extensions fget[c], fput[c].  Extend variable
> check to allow a function reference having a data pointer result.
>
> gcc/fortran/ChangeLog:
>
> PR fortran/100154
> * check.c (variable_check): Allow function reference having a data
> pointer result.
> (arg_strlen_is_zero): New function.
> (gfc_check_fgetputc_sub): Add static check of character and status
> arguments.
> (gfc_check_fgetput_sub): Likewise.
> * intrinsic.c (add_subroutines): Fix argument name for the
> character argument to intrinsic subroutines fget[c], fput[c].
>
> gcc/testsuite/ChangeLog:
>
> PR fortran/100154
> * gfortran.dg/pr100154.f90: New test.
>
>

-- 
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein


[Patch] PR fortran/100154 - [9/10/11/12 Regression] ICE in gfc_conv_procedure_call, at fortran/trans-expr.c:6131

2021-04-22 Thread Harald Anlauf via Gcc-patches
Now with the correct patch attached ...

Sorry for the confusion!

---

Dear Fortranners,

we need to check the arguments to the affected GNU intrinsic extensions
properly, and - as pointed out in the PR by Tobias - we need to allow
function references that have a data pointer result.  Also the argument
names of the character arguments of the subroutine versions needed a
fix ("c" instead of "count").

Regtested on x86_64-pc-linux-gnu.  OK for mainline (12)?
OK for backports after 11.1 release?

Thanks,
Harald


PR fortran/100154 - ICE in gfc_conv_procedure_call, at fortran/trans-expr.c:6131

Add appropriate static checks for the character and status arguments to
the GNU Fortran intrinsic extensions fget[c], fput[c].  Extend variable
check to allow a function reference having a data pointer result.

gcc/fortran/ChangeLog:

PR fortran/100154
* check.c (variable_check): Allow function reference having a data
pointer result.
(arg_strlen_is_zero): New function.
(gfc_check_fgetputc_sub): Add static check of character and status
arguments.
(gfc_check_fgetput_sub): Likewise.
* intrinsic.c (add_subroutines): Fix argument name for the
character argument to intrinsic subroutines fget[c], fput[c].

gcc/testsuite/ChangeLog:

PR fortran/100154
* gfortran.dg/pr100154.f90: New test.

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 82db8e4e1b2..1d30c93df82 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -1055,6 +1055,13 @@ variable_check (gfc_expr *e, int n, bool allow_proc)
  return true;
 }

+  /* F2018:R902: function reference having a data pointer result.  */
+  if (e->expr_type == EXPR_FUNCTION
+  && e->symtree->n.sym->attr.flavor == FL_PROCEDURE
+  && e->symtree->n.sym->attr.function
+  && e->symtree->n.sym->attr.pointer)
+return true;
+
   gfc_error ("%qs argument of %qs intrinsic at %L must be a variable",
 gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic, >where);

@@ -5689,6 +5691,19 @@ gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
functions).  */

+bool
+arg_strlen_is_zero (gfc_expr *c, int n)
+{
+  if (gfc_var_strlen (c) == 0)
+{
+  gfc_error ("%qs argument of %qs intrinsic at %L must have "
+		 "length at least 1", gfc_current_intrinsic_arg[n]->name,
+		 gfc_current_intrinsic, >where);
+  return true;
+}
+  return false;
+}
+
 bool
 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
 {
@@ -5702,13 +5717,19 @@ gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
 return false;
   if (!kind_value_check (c, 1, gfc_default_character_kind))
 return false;
+  if (strcmp (gfc_current_intrinsic, "fgetc") == 0
+  && !variable_check (c, 1, false))
+return false;
+  if (arg_strlen_is_zero (c, 1))
+return false;

   if (status == NULL)
 return true;

   if (!type_check (status, 2, BT_INTEGER)
   || !kind_value_check (status, 2, gfc_default_integer_kind)
-  || !scalar_check (status, 2))
+  || !scalar_check (status, 2)
+  || !variable_check (status, 2, false))
 return false;

   return true;
@@ -5729,13 +5750,19 @@ gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
 return false;
   if (!kind_value_check (c, 0, gfc_default_character_kind))
 return false;
+  if (strcmp (gfc_current_intrinsic, "fget") == 0
+  && !variable_check (c, 0, false))
+return false;
+  if (arg_strlen_is_zero (c, 0))
+return false;

   if (status == NULL)
 return true;

   if (!type_check (status, 1, BT_INTEGER)
   || !kind_value_check (status, 1, gfc_default_integer_kind)
-  || !scalar_check (status, 1))
+  || !scalar_check (status, 1)
+  || !variable_check (status, 1, false))
 return false;

   return true;
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index 17fd92eb462..219f04f2317 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -3460,7 +3460,7 @@ add_subroutines (void)
   /* Argument names.  These are used as argument keywords and so need to
  match the documentation.  Please keep this list in sorted order.  */
   static const char
-*a = "a", *c = "count", *cm = "count_max", *com = "command",
+*a = "a", *c_ = "c", *c = "count", *cm = "count_max", *com = "command",
 *cr = "count_rate", *dt = "date", *errmsg = "errmsg", *f = "from",
 *fp = "frompos", *gt = "get", *h = "harvest", *han = "handler",
 *length = "length", *ln = "len", *md = "mode", *msk = "mask",
@@ -3840,12 +3840,12 @@ add_subroutines (void)
   add_sym_3s ("fgetc", GFC_ISYM_FGETC, CLASS_IMPURE, BT_UNKNOWN, 0, GFC_STD_GNU,
 	  gfc_check_fgetputc_sub, NULL, gfc_resolve_fgetc_sub,
 	  ut, BT_INTEGER, di, REQUIRED, INTENT_IN,
-	  c, BT_CHARACTER, dc, REQUIRED, INTENT_OUT,
+	  c_, BT_CHARACTER, dc, REQUIRED, 

[Patch] PR fortran/100154 - [9/10/11/12 Regression] ICE in gfc_conv_procedure_call, at fortran/trans-expr.c:6131

2021-04-22 Thread Harald Anlauf via Gcc-patches
Dear Fortranners,

we need to check the arguments to the affected GNU intrinsic extensions
properly, and - as pointed out in the PR by Tobias - we need to allow
function references that have a data pointer result.  Also the argument
names of the character arguments of the subroutine versions needed a
fix ("c" instead of "count").

Regtested on x86_64-pc-linux-gnu.  OK for mainline (12)?
OK for backports after 11.1 release?

Thanks,
Harald


PR fortran/100154 - ICE in gfc_conv_procedure_call, at fortran/trans-expr.c:6131

Add appropriate static checks for the character and status arguments to
the GNU Fortran intrinsic extensions fget[c], fput[c].  Extend variable
check to allow a function reference having a data pointer result.

gcc/fortran/ChangeLog:

PR fortran/100154
* check.c (variable_check): Allow function reference having a data
pointer result.
(arg_strlen_is_zero): New function.
(gfc_check_fgetputc_sub): Add static check of character and status
arguments.
(gfc_check_fgetput_sub): Likewise.
* intrinsic.c (add_subroutines): Fix argument name for the
character argument to intrinsic subroutines fget[c], fput[c].

gcc/testsuite/ChangeLog:

PR fortran/100154
* gfortran.dg/pr100154.f90: New test.

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 82db8e4e1b2..1d30c93df82 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -5689,6 +5691,19 @@ gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
 /* Functions for checking FGETC, FPUTC, FGET and FPUT (subroutines and
functions).  */

+bool
+arg_strlen_is_zero (gfc_expr *c, int n)
+{
+  if (gfc_var_strlen (c) == 0)
+{
+  gfc_error ("%qs argument of %qs intrinsic at %L must have "
+		 "length at least 1", gfc_current_intrinsic_arg[n]->name,
+		 gfc_current_intrinsic, >where);
+  return true;
+}
+  return false;
+}
+
 bool
 gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
 {
@@ -5702,13 +5717,19 @@ gfc_check_fgetputc_sub (gfc_expr *unit, gfc_expr *c, gfc_expr *status)
 return false;
   if (!kind_value_check (c, 1, gfc_default_character_kind))
 return false;
+  if (strcmp (gfc_current_intrinsic, "fgetc") == 0
+  && !variable_check (c, 1, false))
+return false;
+  if (arg_strlen_is_zero (c, 1))
+return false;

   if (status == NULL)
 return true;

   if (!type_check (status, 2, BT_INTEGER)
   || !kind_value_check (status, 2, gfc_default_integer_kind)
-  || !scalar_check (status, 2))
+  || !scalar_check (status, 2)
+  || !variable_check (status, 2, false))
 return false;

   return true;
@@ -5729,13 +5750,19 @@ gfc_check_fgetput_sub (gfc_expr *c, gfc_expr *status)
 return false;
   if (!kind_value_check (c, 0, gfc_default_character_kind))
 return false;
+  if (strcmp (gfc_current_intrinsic, "fget") == 0
+  && !variable_check (c, 0, false))
+return false;
+  if (arg_strlen_is_zero (c, 0))
+return false;

   if (status == NULL)
 return true;

   if (!type_check (status, 1, BT_INTEGER)
   || !kind_value_check (status, 1, gfc_default_integer_kind)
-  || !scalar_check (status, 1))
+  || !scalar_check (status, 1)
+  || !variable_check (status, 1, false))
 return false;

   return true;
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index 17fd92eb462..219f04f2317 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -3460,7 +3460,7 @@ add_subroutines (void)
   /* Argument names.  These are used as argument keywords and so need to
  match the documentation.  Please keep this list in sorted order.  */
   static const char
-*a = "a", *c = "count", *cm = "count_max", *com = "command",
+*a = "a", *c_ = "c", *c = "count", *cm = "count_max", *com = "command",
 *cr = "count_rate", *dt = "date", *errmsg = "errmsg", *f = "from",
 *fp = "frompos", *gt = "get", *h = "harvest", *han = "handler",
 *length = "length", *ln = "len", *md = "mode", *msk = "mask",
@@ -3840,12 +3840,12 @@ add_subroutines (void)
   add_sym_3s ("fgetc", GFC_ISYM_FGETC, CLASS_IMPURE, BT_UNKNOWN, 0, GFC_STD_GNU,
 	  gfc_check_fgetputc_sub, NULL, gfc_resolve_fgetc_sub,
 	  ut, BT_INTEGER, di, REQUIRED, INTENT_IN,
-	  c, BT_CHARACTER, dc, REQUIRED, INTENT_OUT,
+	  c_, BT_CHARACTER, dc, REQUIRED, INTENT_OUT,
 	  st, BT_INTEGER, di, OPTIONAL, INTENT_OUT);

   add_sym_2s ("fget", GFC_ISYM_FGET, CLASS_IMPURE, BT_UNKNOWN, 0, GFC_STD_GNU,
 	  gfc_check_fgetput_sub, NULL, gfc_resolve_fget_sub,
-	  c, BT_CHARACTER, dc, REQUIRED, INTENT_OUT,
+	  c_, BT_CHARACTER, dc, REQUIRED, INTENT_OUT,
 	  st, BT_INTEGER, di, OPTIONAL, INTENT_OUT);

   add_sym_1s ("flush", GFC_ISYM_FLUSH, CLASS_IMPURE, BT_UNKNOWN, 0, GFC_STD_GNU,
@@ -3855,12 +3855,12 @@ add_subroutines (void)
   add_sym_3s ("fputc", GFC_ISYM_FPUTC, CLASS_IMPURE, BT_UNKNOWN, 0, GFC_STD_GNU,
 	  gfc_check_fgetputc_sub, NULL,