Always use locations from get and put arguments for error messages.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 14 Jun 2020 12:39:03 +0000 (14:39 +0200)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 14 Jun 2020 12:39:03 +0000 (14:39 +0200)
A simple and obvios patch - the error location was taken
from a variable that was not initialized for optional
variables.

gcc/fortran/ChangeLog:

* check.c (gfc_check_random_seed): Always use locations
from get and put arguments for error messages.

gcc/testsuite/ChangeLog:

* gfortran.dg/random_seed_4.f90: New test.

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

index 148a326..9c95524 100644 (file)
@@ -6643,7 +6643,7 @@ gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
        gfc_error ("Size of %qs argument of %qs intrinsic at %L "
                   "too small (%i/%i)",
                   gfc_current_intrinsic_arg[1]->name, gfc_current_intrinsic,
-                  where, (int) mpz_get_ui (put_size), seed_size);
+                  &put->where, (int) mpz_get_ui (put_size), seed_size);
     }
 
   if (get != NULL)
@@ -6675,7 +6675,7 @@ gfc_check_random_seed (gfc_expr *size, gfc_expr *put, gfc_expr *get)
        gfc_error ("Size of %qs argument of %qs intrinsic at %L "
                   "too small (%i/%i)",
                   gfc_current_intrinsic_arg[2]->name, gfc_current_intrinsic,
-                  where, (int) mpz_get_ui (get_size), seed_size);
+                  &get->where, (int) mpz_get_ui (get_size), seed_size);
     }
 
   /* RANDOM_SEED may not have more than one non-optional argument.  */
diff --git a/gcc/testsuite/gfortran.dg/random_seed_4.f90 b/gcc/testsuite/gfortran.dg/random_seed_4.f90
new file mode 100644 (file)
index 0000000..4c3afe5
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! PR fortran/95037
+! This led to a segfault or a confusing error message.  Original
+! test case by Bill Long.
+
+subroutine my_random_seed_v (size, put, get)
+integer, optional :: size
+integer, optional :: put(1)
+integer, optional :: get(1)
+call random_seed (size, get=get) ! { dg-error "too small" }
+call random_seed (size, put=put) ! { dg-error "too small" }
+call random_seed (size, get=get, put=put) ! { dg-error "too small" }
+end subroutine my_random_seed_v
+