* [Bug fortran/85130] Substrings out of range are not rejected
[not found] <bug-85130-4@http.gcc.gnu.org/bugzilla/>
@ 2021-09-10 21:29 ` anlauf at gcc dot gnu.org
2021-09-11 18:42 ` anlauf at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-09-10 21:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85130
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
CC| |anlauf at gcc dot gnu.org
--- Comment #4 from anlauf at gcc dot gnu.org ---
F2018 has the following changed text in 9.4.1 Substrings:
... If the starting point is greater than the ending point, the substring
has length zero; otherwise, both the starting point and the ending point
shall be within the range 1, 2, ..., n. ...
Thus the following code would be legal:
character(5), parameter :: c0(1) = [ "12345" ]
print *, c0(1)(-5:-8)
end
and print an empty string, while it currently prints junk.
It does the right thing with current trunk when parameter is removed, though.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/85130] Substrings out of range are not rejected
[not found] <bug-85130-4@http.gcc.gnu.org/bugzilla/>
2021-09-10 21:29 ` [Bug fortran/85130] Substrings out of range are not rejected anlauf at gcc dot gnu.org
@ 2021-09-11 18:42 ` anlauf at gcc dot gnu.org
2021-09-12 18:40 ` anlauf at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-09-11 18:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85130
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |anlauf at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #5 from anlauf at gcc dot gnu.org ---
We should handle the substring bounds as signed instead of unsigned.
This is obviously fixed by:
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index dfecc3012e1..604e63e6164 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -1724,8 +1724,8 @@ find_substring_ref (gfc_expr *p, gfc_expr **newp)
*newp = gfc_copy_expr (p);
free ((*newp)->value.character.string);
- end = (gfc_charlen_t) mpz_get_ui (p->ref->u.ss.end->value.integer);
- start = (gfc_charlen_t) mpz_get_ui (p->ref->u.ss.start->value.integer);
+ end = (gfc_charlen_t) mpz_get_si (p->ref->u.ss.end->value.integer);
+ start = (gfc_charlen_t) mpz_get_si (p->ref->u.ss.start->value.integer);
if (end >= start)
length = end - start + 1;
else
and regtests cleanly. :-)
@Thomas: although the wording is slightly different between F2003 and F2018, it
always results in length zero if the starting point exceeds the ending point.
Would you agree in reverting your commit r258976 after applying the above?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/85130] Substrings out of range are not rejected
[not found] <bug-85130-4@http.gcc.gnu.org/bugzilla/>
2021-09-10 21:29 ` [Bug fortran/85130] Substrings out of range are not rejected anlauf at gcc dot gnu.org
2021-09-11 18:42 ` anlauf at gcc dot gnu.org
@ 2021-09-12 18:40 ` anlauf at gcc dot gnu.org
2021-09-13 17:27 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-09-12 18:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85130
--- Comment #6 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2021-September/056500.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/85130] Substrings out of range are not rejected
[not found] <bug-85130-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2021-09-12 18:40 ` anlauf at gcc dot gnu.org
@ 2021-09-13 17:27 ` cvs-commit at gcc dot gnu.org
2021-09-16 18:20 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-13 17:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85130
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:8d93ba93d3b13ac3d3c34404cad87732c809605b
commit r12-3499-g8d93ba93d3b13ac3d3c34404cad87732c809605b
Author: Harald Anlauf <anlauf@gmx.de>
Date: Mon Sep 13 19:26:35 2021 +0200
Fortran - fix handling of substring start and end indices
gcc/fortran/ChangeLog:
PR fortran/85130
* expr.c (find_substring_ref): Handle given substring start and
end indices as signed integers, not unsigned.
gcc/testsuite/ChangeLog:
PR fortran/85130
* gfortran.dg/substr_6.f90: Revert commit r8-7574, adding again
test that was erroneously considered as illegal.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/85130] Substrings out of range are not rejected
[not found] <bug-85130-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2021-09-13 17:27 ` cvs-commit at gcc dot gnu.org
@ 2021-09-16 18:20 ` cvs-commit at gcc dot gnu.org
2021-09-21 19:15 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-16 18:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85130
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:3bc4ed085145e1cb6089841c811094633eea7431
commit r11-9009-g3bc4ed085145e1cb6089841c811094633eea7431
Author: Harald Anlauf <anlauf@gmx.de>
Date: Mon Sep 13 19:26:35 2021 +0200
Fortran - fix handling of substring start and end indices
gcc/fortran/ChangeLog:
PR fortran/85130
* expr.c (find_substring_ref): Handle given substring start and
end indices as signed integers, not unsigned.
gcc/testsuite/ChangeLog:
PR fortran/85130
* gfortran.dg/substr_6.f90: Revert commit r8-7574, adding again
test that was erroneously considered as illegal.
(cherry picked from commit 8d93ba93d3b13ac3d3c34404cad87732c809605b)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/85130] Substrings out of range are not rejected
[not found] <bug-85130-4@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
2021-09-16 18:20 ` cvs-commit at gcc dot gnu.org
@ 2021-09-21 19:15 ` cvs-commit at gcc dot gnu.org
2021-09-21 19:18 ` cvs-commit at gcc dot gnu.org
2021-09-21 19:19 ` anlauf at gcc dot gnu.org
7 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-21 19:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85130
--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:a1591a283767168982ff60414ee01aaa1400fbf8
commit r10-10142-ga1591a283767168982ff60414ee01aaa1400fbf8
Author: Harald Anlauf <anlauf@gmx.de>
Date: Mon Sep 13 19:26:35 2021 +0200
Fortran - fix handling of substring start and end indices
gcc/fortran/ChangeLog:
PR fortran/85130
* expr.c (find_substring_ref): Handle given substring start and
end indices as signed integers, not unsigned.
gcc/testsuite/ChangeLog:
PR fortran/85130
* gfortran.dg/substr_6.f90: Revert commit r8-7574, adding again
test that was erroneously considered as illegal.
(cherry picked from commit 8d93ba93d3b13ac3d3c34404cad87732c809605b)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/85130] Substrings out of range are not rejected
[not found] <bug-85130-4@http.gcc.gnu.org/bugzilla/>
` (5 preceding siblings ...)
2021-09-21 19:15 ` cvs-commit at gcc dot gnu.org
@ 2021-09-21 19:18 ` cvs-commit at gcc dot gnu.org
2021-09-21 19:19 ` anlauf at gcc dot gnu.org
7 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-21 19:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85130
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:0fabf86a52c46db19026a956cf386da46fa4d0be
commit r9-9738-g0fabf86a52c46db19026a956cf386da46fa4d0be
Author: Harald Anlauf <anlauf@gmx.de>
Date: Mon Sep 13 19:26:35 2021 +0200
Fortran - fix handling of substring start and end indices
gcc/fortran/ChangeLog:
PR fortran/85130
* expr.c (find_substring_ref): Handle given substring start and
end indices as signed integers, not unsigned.
gcc/testsuite/ChangeLog:
PR fortran/85130
* gfortran.dg/substr_6.f90: Revert commit r8-7574, adding again
test that was erroneously considered as illegal.
(cherry picked from commit 8d93ba93d3b13ac3d3c34404cad87732c809605b)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/85130] Substrings out of range are not rejected
[not found] <bug-85130-4@http.gcc.gnu.org/bugzilla/>
` (6 preceding siblings ...)
2021-09-21 19:18 ` cvs-commit at gcc dot gnu.org
@ 2021-09-21 19:19 ` anlauf at gcc dot gnu.org
7 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-09-21 19:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85130
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |9.5
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #11 from anlauf at gcc dot gnu.org ---
Fixed on all open branches. Closing.
^ permalink raw reply [flat|nested] 8+ messages in thread