public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/113245] New: SIZE with optional DIM argument that has the OPTIONAL+VALUE attributes
@ 2024-01-05 19:31 anlauf at gcc dot gnu.org
2024-01-05 19:31 ` [Bug fortran/113245] " anlauf at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-01-05 19:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113245
Bug ID: 113245
Summary: SIZE with optional DIM argument that has the
OPTIONAL+VALUE attributes
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: anlauf at gcc dot gnu.org
Target Milestone: ---
Related to pr30865, but with optional that has the VALUE attribute.
Testcase:
program p
implicit none
real :: a(2,3)
call ref (a,2) ! works
call val (a,2) ! works
print *, "--"
call ref (a) ! works
call val (a) ! fails
contains
subroutine ref (x, d)
real, intent(in) :: x(:,:)
integer, optional, intent(in) :: d
print *, "present (d) =", present (d)
print *, "size (a, d) =", size (x, dim=d)
end
subroutine val (x, d)
real, intent(in) :: x(:,:)
integer, optional, value :: d
print *, "present (d) =", present (d)
print *, "size (a, d) =", size (x, dim=d) ! <<< miscompiled
end
end
The dump-tree shows that the presence test is miscompiled, leading to
always accessing 'd', which is 0 for an absent argument, and causing an
invalid access.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/113245] SIZE with optional DIM argument that has the OPTIONAL+VALUE attributes
2024-01-05 19:31 [Bug fortran/113245] New: SIZE with optional DIM argument that has the OPTIONAL+VALUE attributes anlauf at gcc dot gnu.org
@ 2024-01-05 19:31 ` anlauf at gcc dot gnu.org
2024-01-07 20:26 ` anlauf at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-01-05 19:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113245
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P4
Keywords| |wrong-code
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/113245] SIZE with optional DIM argument that has the OPTIONAL+VALUE attributes
2024-01-05 19:31 [Bug fortran/113245] New: SIZE with optional DIM argument that has the OPTIONAL+VALUE attributes anlauf at gcc dot gnu.org
2024-01-05 19:31 ` [Bug fortran/113245] " anlauf at gcc dot gnu.org
@ 2024-01-07 20:26 ` anlauf at gcc dot gnu.org
2024-01-07 21:35 ` anlauf at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-01-07 20:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113245
--- Comment #1 from anlauf at gcc dot gnu.org ---
The following probably rather obvious patch fixes the issue:
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index d973c49380c..748cc74de89 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -8025,9 +8092,7 @@ gfc_conv_intrinsic_size (gfc_se * se, gfc_expr * expr)
argse.data_not_needed = 1;
gfc_conv_expr (&argse, actual->expr);
gfc_add_block_to_block (&se->pre, &argse.pre);
- cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node,
- argse.expr, null_pointer_node);
- cond = gfc_evaluate_now (cond, &se->pre);
+ cond = gfc_conv_expr_present (actual->expr->symtree->n.sym);
/* 'block2' contains the arg2 absent case, 'block' the arg2 present
case; size_var can be used in both blocks. */
tree size_var = gfc_create_var (TREE_TYPE (size), "size");
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/113245] SIZE with optional DIM argument that has the OPTIONAL+VALUE attributes
2024-01-05 19:31 [Bug fortran/113245] New: SIZE with optional DIM argument that has the OPTIONAL+VALUE attributes anlauf at gcc dot gnu.org
2024-01-05 19:31 ` [Bug fortran/113245] " anlauf at gcc dot gnu.org
2024-01-07 20:26 ` anlauf at gcc dot gnu.org
@ 2024-01-07 21:35 ` anlauf at gcc dot gnu.org
2024-01-08 17:50 ` cvs-commit at gcc dot gnu.org
2024-01-08 20:45 ` anlauf at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-01-07 21:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113245
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-01-07
Assignee|unassigned at gcc dot gnu.org |anlauf at gcc dot gnu.org
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
--- Comment #2 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2024-January/060096.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/113245] SIZE with optional DIM argument that has the OPTIONAL+VALUE attributes
2024-01-05 19:31 [Bug fortran/113245] New: SIZE with optional DIM argument that has the OPTIONAL+VALUE attributes anlauf at gcc dot gnu.org
` (2 preceding siblings ...)
2024-01-07 21:35 ` anlauf at gcc dot gnu.org
@ 2024-01-08 17:50 ` cvs-commit at gcc dot gnu.org
2024-01-08 20:45 ` anlauf at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-08 17:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113245
--- Comment #3 from GCC 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:0056458550ba6df0a339589736729be8b886790a
commit r14-7008-g0056458550ba6df0a339589736729be8b886790a
Author: Harald Anlauf <anlauf@gmx.de>
Date: Sun Jan 7 22:24:25 2024 +0100
Fortran: SIZE optional DIM argument having OPTIONAL+VALUE attributes
[PR113245]
gcc/fortran/ChangeLog:
PR fortran/113245
* trans-intrinsic.cc (gfc_conv_intrinsic_size): Use
gfc_conv_expr_present() for proper check of optional DIM argument.
gcc/testsuite/ChangeLog:
PR fortran/113245
* gfortran.dg/size_optional_dim_2.f90: New test.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/113245] SIZE with optional DIM argument that has the OPTIONAL+VALUE attributes
2024-01-05 19:31 [Bug fortran/113245] New: SIZE with optional DIM argument that has the OPTIONAL+VALUE attributes anlauf at gcc dot gnu.org
` (3 preceding siblings ...)
2024-01-08 17:50 ` cvs-commit at gcc dot gnu.org
@ 2024-01-08 20:45 ` anlauf at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-01-08 20:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113245
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|--- |14.0
Status|ASSIGNED |RESOLVED
--- Comment #4 from anlauf at gcc dot gnu.org ---
Fixed.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-01-08 20:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-05 19:31 [Bug fortran/113245] New: SIZE with optional DIM argument that has the OPTIONAL+VALUE attributes anlauf at gcc dot gnu.org
2024-01-05 19:31 ` [Bug fortran/113245] " anlauf at gcc dot gnu.org
2024-01-07 20:26 ` anlauf at gcc dot gnu.org
2024-01-07 21:35 ` anlauf at gcc dot gnu.org
2024-01-08 17:50 ` cvs-commit at gcc dot gnu.org
2024-01-08 20:45 ` anlauf at gcc dot gnu.org
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).