public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-coroutines] 2020-8-20 José Rui Faustino de Sousa <jrfsousa@gmail.com>
@ 2020-08-31 19:49 Iain D Sandoe
0 siblings, 0 replies; 4+ messages in thread
From: Iain D Sandoe @ 2020-08-31 19:49 UTC (permalink / raw)
To: gcc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 2100 bytes --]
https://gcc.gnu.org/g:3a7a95a220c14043da1e1166530e1d76f001dad9
commit 3a7a95a220c14043da1e1166530e1d76f001dad9
Author: José Rui Faustino de Sousa <jrfsousa@gmail.com>
Date: Sun Aug 30 18:03:13 2020 +0000
2020-8-20 José Rui Faustino de Sousa <jrfsousa@gmail.com>
gcc/fortran/ChangeLog:
PR fortran/96727
* expr.c (gfc_check_init_expr): Add default error message for the AS_ASSUMED_RANK case.
gcc/testsuite/ChangeLog:
PR fortran/96727
* gfortran.dg/PR96727.f90: New test.
Diff:
---
gcc/fortran/expr.c | 6 ++++++
gcc/testsuite/gfortran.dg/PR96727.f90 | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 2ef01f0f14f..68784a235f1 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -3007,6 +3007,12 @@ gfc_check_init_expr (gfc_expr *e)
e->symtree->n.sym->name, &e->where);
break;
+ case AS_ASSUMED_RANK:
+ gfc_error ("Assumed-rank array %qs at %L is not permitted "
+ "in an initialization expression",
+ e->symtree->n.sym->name, &e->where);
+ break;
+
default:
gcc_unreachable();
}
diff --git a/gcc/testsuite/gfortran.dg/PR96727.f90 b/gcc/testsuite/gfortran.dg/PR96727.f90
new file mode 100644
index 00000000000..d45dbb7ccd6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR96727.f90
@@ -0,0 +1,34 @@
+! { dg-do run }
+!
+! Test the fix for PR96727
+!
+
+program cref_p
+
+ implicit none
+
+ integer :: i
+
+ integer, parameter :: n = 3
+ integer, parameter :: p(*) = [(i, i=1,n*n)]
+ character(len=*), parameter :: q = repeat('a', n*n)
+
+ integer :: a(n,n)
+ character(len=n*n) :: c
+
+ a = reshape(p, shape=[n,n])
+ call csub(a, c)
+ if (c/=q) stop 1
+ stop
+
+contains
+
+ subroutine csub(a, b)
+ integer, intent(in) :: a(..)
+ character(len=size(a)), intent(out) :: b
+
+ b = repeat('a', len(b))
+ return
+ end subroutine csub
+
+end program cref_p
^ permalink raw reply [flat|nested] 4+ messages in thread
* [gcc/devel/c++-coroutines] 2020-8-20 José Rui Faustino de Sousa <jrfsousa@gmail.com>
@ 2020-08-31 19:49 Iain D Sandoe
0 siblings, 0 replies; 4+ messages in thread
From: Iain D Sandoe @ 2020-08-31 19:49 UTC (permalink / raw)
To: gcc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 3392 bytes --]
https://gcc.gnu.org/g:a240e83ce9d92786ac9a15ab815b58197b85ada2
commit a240e83ce9d92786ac9a15ab815b58197b85ada2
Author: José Rui Faustino de Sousa <jrfsousa@gmail.com>
Date: Sun Aug 30 18:10:15 2020 +0000
2020-8-20 José Rui Faustino de Sousa <jrfsousa@gmail.com>
gcc/fortran/ChangeLog:
PR fortran/96728
* module.c (module_peek_char): Peek ahead function.
(parse_integer): Add code for parsing signed integers.
(parse_atom): Add code to handle signed integers.
(peek_atom): Add code to handle signed integers.
gcc/testsuite/ChangeLog:
PR fortran/96728
* gfortran.dg/PR96728.f90: New test.
Diff:
---
gcc/fortran/module.c | 42 +++++++++++++++++++++++++++++-
gcc/testsuite/gfortran.dg/PR96728.f90 | 49 +++++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+), 1 deletion(-)
diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c
index 714fbd9c299..33e7df7d6a4 100644
--- a/gcc/fortran/module.c
+++ b/gcc/fortran/module.c
@@ -1234,6 +1234,13 @@ get_module_locus (module_locus *m)
m->pos = module_pos;
}
+/* Peek at the next character in the module. */
+
+static int
+module_peek_char (void)
+{
+ return module_content[module_pos];
+}
/* Get the next character in the module, updating our reckoning of
where we are. */
@@ -1314,7 +1321,19 @@ parse_string (void)
static void
parse_integer (int c)
{
- atom_int = c - '0';
+ int sign = 1;
+
+ atom_int = 0;
+ switch (c)
+ {
+ case ('-'):
+ sign = -1;
+ case ('+'):
+ break;
+ default:
+ atom_int = c - '0';
+ break;
+ }
for (;;)
{
@@ -1328,6 +1347,7 @@ parse_integer (int c)
atom_int = 10 * atom_int + c - '0';
}
+ atom_int *= sign;
}
@@ -1401,6 +1421,16 @@ parse_atom (void)
parse_integer (c);
return ATOM_INTEGER;
+ case '+':
+ case '-':
+ if (ISDIGIT (module_peek_char ()))
+ {
+ parse_integer (c);
+ return ATOM_INTEGER;
+ }
+ else
+ bad_module ("Bad name");
+
case 'a':
case 'b':
case 'c':
@@ -1504,6 +1534,16 @@ peek_atom (void)
module_unget_char ();
return ATOM_INTEGER;
+ case '+':
+ case '-':
+ if (ISDIGIT (module_peek_char ()))
+ {
+ module_unget_char ();
+ return ATOM_INTEGER;
+ }
+ else
+ bad_module ("Bad name");
+
case 'a':
case 'b':
case 'c':
diff --git a/gcc/testsuite/gfortran.dg/PR96728.f90 b/gcc/testsuite/gfortran.dg/PR96728.f90
new file mode 100644
index 00000000000..4caa3a569a7
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR96728.f90
@@ -0,0 +1,49 @@
+! { dg-do run }
+!
+! Test the fix for PR96728
+!
+
+module cref_m
+
+ implicit none
+
+ private
+
+ public :: &
+ isub_a_m
+
+contains
+
+ subroutine isub_a_m(a, b)
+ integer, intent(in) :: a(..)
+ integer, intent(out) :: b(size(a))
+
+ integer :: i
+
+ b = [(i, i=1,size(b))]
+ return
+ end subroutine isub_a_m
+
+end module cref_m
+
+program cref_p
+
+ use cref_m, only: &
+ isub_a_m
+
+ implicit none
+
+ integer :: i
+
+ integer, parameter :: n = 3
+ integer, parameter :: p(*) = [(i, i=1,n*n)]
+
+ integer :: a(n,n)
+ integer :: b(n*n)
+
+ a = reshape(p, shape=[n,n])
+ call isub_a_m(a, b)
+ if (any(b/=p)) stop 1
+ stop
+
+end program cref_p
^ permalink raw reply [flat|nested] 4+ messages in thread
* [gcc/devel/c++-coroutines] 2020-8-20 José Rui Faustino de Sousa <jrfsousa@gmail.com>
@ 2020-08-31 19:49 Iain D Sandoe
0 siblings, 0 replies; 4+ messages in thread
From: Iain D Sandoe @ 2020-08-31 19:49 UTC (permalink / raw)
To: gcc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 2568 bytes --]
https://gcc.gnu.org/g:8f7d99acf6d94eed6a7f9b9f76bd4c2243c660b2
commit 8f7d99acf6d94eed6a7f9b9f76bd4c2243c660b2
Author: José Rui Faustino de Sousa <jrfsousa@gmail.com>
Date: Sun Aug 30 17:58:13 2020 +0000
2020-8-20 José Rui Faustino de Sousa <jrfsousa@gmail.com>
gcc/fortran/ChangeLog:
PR fortran/96726
* expr.c (check_references): Change different relational operator
to less-than operator to avoid infinite loop.
gcc/testsuite/ChangeLog:
PR fortran/96726
* gfortran.dg/PR96726.f90: New test.
Diff:
---
gcc/fortran/expr.c | 2 +-
gcc/testsuite/gfortran.dg/PR96726.f90 | 72 +++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 6707ca550a0..2ef01f0f14f 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -3273,7 +3273,7 @@ check_references (gfc_ref* ref, bool (*checker) (gfc_expr*))
switch (ref->type)
{
case REF_ARRAY:
- for (dim = 0; dim != ref->u.ar.dimen; ++dim)
+ for (dim = 0; dim < ref->u.ar.dimen; ++dim)
{
if (!checker (ref->u.ar.start[dim]))
return false;
diff --git a/gcc/testsuite/gfortran.dg/PR96726.f90 b/gcc/testsuite/gfortran.dg/PR96726.f90
new file mode 100644
index 00000000000..b0b26b90669
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR96726.f90
@@ -0,0 +1,72 @@
+! { dg-do run }
+!
+! Test the fix for PR96726
+!
+
+module cref_m
+
+ implicit none
+
+ private
+
+ public :: &
+ sizeish
+
+contains
+
+ pure function sizeish(a) result(s)
+ integer, intent(in) :: a(..)
+
+ integer :: s
+
+ s = size(a)
+ return
+ end function sizeish
+
+end module cref_m
+
+program cref_p
+
+ use cref_m, only: &
+ sizeish
+
+ implicit none
+
+ integer :: i
+
+ integer, parameter :: n = 3
+ integer, parameter :: p(*) = [(i, i=1,n*n)]
+
+ integer :: a(n,n)
+ integer :: b(n*n)
+
+ a = reshape(p, shape=[n,n])
+ call isub_a(a, b)
+ if (any(b/=p)) stop 1
+ call isub_b(a, b)
+ if (any(b/=p)) stop 2
+ stop
+
+contains
+
+ subroutine isub_a(a, b)
+ integer, intent(in) :: a(..)
+ integer, intent(out) :: b(size(a))
+
+ integer :: i
+
+ b = [(i, i=1,size(b))]
+ return
+ end subroutine isub_a
+
+ subroutine isub_b(a, b)
+ integer, intent(in) :: a(..)
+ integer, intent(out) :: b(sizeish(a))
+
+ integer :: i
+
+ b = [(i, i=1,sizeish(b))]
+ return
+ end subroutine isub_b
+
+end program cref_p
^ permalink raw reply [flat|nested] 4+ messages in thread
* [gcc/devel/c++-coroutines] 2020-8-20 José Rui Faustino de Sousa <jrfsousa@gmail.com>
@ 2020-08-31 19:49 Iain D Sandoe
0 siblings, 0 replies; 4+ messages in thread
From: Iain D Sandoe @ 2020-08-31 19:49 UTC (permalink / raw)
To: gcc-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 3608 bytes --]
https://gcc.gnu.org/g:8e1be7efcb1c68dd82e2b2c1bcf3e5ace245654d
commit 8e1be7efcb1c68dd82e2b2c1bcf3e5ace245654d
Author: José Rui Faustino de Sousa <jrfsousa@gmail.com>
Date: Sun Aug 30 17:28:08 2020 +0000
2020-8-20 José Rui Faustino de Sousa <jrfsousa@gmail.com>
gcc/fortran/ChangeLog:
PR fortran/94110
* interface.c (gfc_compare_actual_formal): Add code to also raise
the actual argument cannot be an assumed-size array error when the
dummy arguments are deferred-shape or assumed-rank pointer.
gcc/testsuite/ChangeLog:
PR fortran/94110
* gfortran.dg/PR94110.f90: New test.
Diff:
---
gcc/fortran/interface.c | 5 +-
gcc/testsuite/gfortran.dg/PR94110.f90 | 88 +++++++++++++++++++++++++++++++++++
2 files changed, 92 insertions(+), 1 deletion(-)
diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index 7985fc70fd4..020cdd73df8 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -3303,7 +3303,10 @@ gfc_compare_actual_formal (gfc_actual_arglist **ap, gfc_formal_arglist *formal,
return false;
}
- if (f->sym->as && f->sym->as->type == AS_ASSUMED_SHAPE
+ if (f->sym->as
+ && (f->sym->as->type == AS_ASSUMED_SHAPE
+ || f->sym->as->type == AS_DEFERRED
+ || (f->sym->as->type == AS_ASSUMED_RANK && f->sym->attr.pointer))
&& a->expr->expr_type == EXPR_VARIABLE
&& a->expr->symtree->n.sym->as
&& a->expr->symtree->n.sym->as->type == AS_ASSUMED_SIZE
diff --git a/gcc/testsuite/gfortran.dg/PR94110.f90 b/gcc/testsuite/gfortran.dg/PR94110.f90
new file mode 100644
index 00000000000..9ec70ec857e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR94110.f90
@@ -0,0 +1,88 @@
+! { dg-do compile }
+!
+! Test the fix for PR94110
+!
+
+program asa_p
+
+ implicit none
+
+ integer, parameter :: n = 7
+
+ integer :: p(n)
+ integer :: s
+
+ p = 1
+ s = sumf_as(p)
+ if (s/=n) stop 1
+ s = sumf_ar(p)
+ if (s/=n) stop 2
+ stop
+
+contains
+
+ function sumf_as(a) result(s)
+ integer, target, intent(in) :: a(*)
+
+ integer :: s
+
+ s = sum_as(a) ! { dg-error "Actual argument for .a. cannot be an assumed-size array" }
+ s = sum_p_ds(a) ! { dg-error "Actual argument for .a. cannot be an assumed-size array" }
+ s = sum_p_ar(a) ! { dg-error "Actual argument for .a. cannot be an assumed-size array" }
+ return
+ end function sumf_as
+
+ function sumf_ar(a) result(s)
+ integer, target, intent(in) :: a(..)
+
+ integer :: s
+
+ select rank(a)
+ rank(*)
+ s = sum_as(a) ! { dg-error "Actual argument for .a. cannot be an assumed-size array" }
+ s = sum_p_ds(a) ! { dg-error "Actual argument for .a. cannot be an assumed-size array" }
+ s = sum_p_ar(a) ! { dg-error "Actual argument for .a. cannot be an assumed-size array" }
+ rank default
+ stop 3
+ end select
+ return
+ end function sumf_ar
+
+ function sum_as(a) result(s)
+ integer, intent(in) :: a(:)
+
+ integer :: s
+
+ s = sum(a)
+ return
+ end function sum_as
+
+ function sum_p_ds(a) result(s)
+ integer, pointer, intent(in) :: a(:)
+
+ integer :: s
+
+ s = -1
+ if(associated(a))&
+ s = sum(a)
+ return
+ end function sum_p_ds
+
+ function sum_p_ar(a) result(s)
+ integer, pointer, intent(in) :: a(..)
+
+ integer :: s
+
+ s = -1
+ select rank(a)
+ rank(1)
+ if(associated(a))&
+ s = sum(a)
+ rank default
+ stop 4
+ end select
+ return
+ end function sum_p_ar
+
+end program asa_p
+
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-08-31 19:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31 19:49 [gcc/devel/c++-coroutines] 2020-8-20 José Rui Faustino de Sousa <jrfsousa@gmail.com> Iain D Sandoe
-- strict thread matches above, loose matches on Subject: below --
2020-08-31 19:49 Iain D Sandoe
2020-08-31 19:49 Iain D Sandoe
2020-08-31 19:49 Iain D Sandoe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).