public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/57360] New: Implement a warning for implied save
@ 2013-05-21 18:42 Joost.VandeVondele at mat dot ethz.ch
2015-10-20 21:46 ` [Bug fortran/57360] " dominiq at lps dot ens.fr
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2013-05-21 18:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57360
Bug ID: 57360
Summary: Implement a warning for implied save
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: Joost.VandeVondele at mat dot ethz.ch
The following is a code snippet with an implicit save for the variable I.
SUBROUTINE T()
INTEGER :: I=1
WRITE(6,*) I
I=I+1
END SUBROUTINE T
CALL T()
CALL T()
END
Expecting this code to print twice 1 is one of the common mistakes for (C)
programmers starting with Fortran, see e.g.
http://www.cs.rpi.edu/~szymansk/OOF90/bugs.html
It would be nice if the compiler could optionally (-Wextra?) emit a warning for
implicit save attributes. Obviously the explicit code 'INTEGER, SAVE :: I=1'
should be fine.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/57360] Implement a warning for implied save
2013-05-21 18:42 [Bug fortran/57360] New: Implement a warning for implied save Joost.VandeVondele at mat dot ethz.ch
@ 2015-10-20 21:46 ` dominiq at lps dot ens.fr
2015-10-21 19:11 ` anlauf at gmx dot de
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-10-20 21:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57360
Dominique d'Humieres <dominiq at lps dot ens.fr> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2015-10-20
Ever confirmed|0 |1
--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Usual answer!
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/57360] Implement a warning for implied save
2013-05-21 18:42 [Bug fortran/57360] New: Implement a warning for implied save Joost.VandeVondele at mat dot ethz.ch
2015-10-20 21:46 ` [Bug fortran/57360] " dominiq at lps dot ens.fr
@ 2015-10-21 19:11 ` anlauf at gmx dot de
2015-10-22 5:45 ` Joost.VandeVondele at mat dot ethz.ch
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gmx dot de @ 2015-10-21 19:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57360
Harald Anlauf <anlauf at gmx dot de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |anlauf at gmx dot de
--- Comment #2 from Harald Anlauf <anlauf at gmx dot de> ---
I have a quite common "counter example", where a subroutine
is initialized on first invocation:
subroutine foo ()
logical :: first = .true.
write(6,*) first
if (first) then
first = .false.
! Do initialization
end if
end subroutine foo
call foo ()
call foo ()
end
Should this one also get a warning?
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/57360] Implement a warning for implied save
2013-05-21 18:42 [Bug fortran/57360] New: Implement a warning for implied save Joost.VandeVondele at mat dot ethz.ch
2015-10-20 21:46 ` [Bug fortran/57360] " dominiq at lps dot ens.fr
2015-10-21 19:11 ` anlauf at gmx dot de
@ 2015-10-22 5:45 ` Joost.VandeVondele at mat dot ethz.ch
2021-10-07 20:41 ` anlauf at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2015-10-22 5:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57360
Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |Joost.VandeVondele at mat dot ethz
| |.ch
--- Comment #3 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> ---
(In reply to Harald Anlauf from comment #2)
> I have a quite common "counter example"
> Should this one also get a warning?
yes, while there are plenty of good uses of saved variables (really?), it
should be made more explicit i.e. just write
logical, save :: first = .true.
as often with warnings, expert programmers won't need them, but novices might
(and they are useful to enforce good coding style with -Werror=foo). It is
certainly something I would add to the enforce list for our project.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/57360] Implement a warning for implied save
2013-05-21 18:42 [Bug fortran/57360] New: Implement a warning for implied save Joost.VandeVondele at mat dot ethz.ch
` (2 preceding siblings ...)
2015-10-22 5:45 ` Joost.VandeVondele at mat dot ethz.ch
@ 2021-10-07 20:41 ` anlauf at gcc dot gnu.org
2024-01-20 18:51 ` w6ws at earthlink dot net
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-10-07 20:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57360
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |vivekrao4 at yahoo dot com
--- Comment #4 from anlauf at gcc dot gnu.org ---
*** Bug 102638 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/57360] Implement a warning for implied save
2013-05-21 18:42 [Bug fortran/57360] New: Implement a warning for implied save Joost.VandeVondele at mat dot ethz.ch
` (3 preceding siblings ...)
2021-10-07 20:41 ` anlauf at gcc dot gnu.org
@ 2024-01-20 18:51 ` w6ws at earthlink dot net
2024-01-20 22:16 ` kargl at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: w6ws at earthlink dot net @ 2024-01-20 18:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57360
--- Comment #5 from Walter Spector <w6ws at earthlink dot net> ---
IMHO this should be a "surprising" warning when -Wsurprising is specified.
The message should suggest adding an explicit SAVE attribute to make the code
clear.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/57360] Implement a warning for implied save
2013-05-21 18:42 [Bug fortran/57360] New: Implement a warning for implied save Joost.VandeVondele at mat dot ethz.ch
` (4 preceding siblings ...)
2024-01-20 18:51 ` w6ws at earthlink dot net
@ 2024-01-20 22:16 ` kargl at gcc dot gnu.org
2024-01-21 17:43 ` kargl at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: kargl at gcc dot gnu.org @ 2024-01-20 22:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57360
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |kargl at gcc dot gnu.org
--- Comment #6 from kargl at gcc dot gnu.org ---
With this patch,
diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 503ecb8d9b5..abb3579893f 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -2278,7 +2278,12 @@ add_init_expr_to_sym (const char *name, gfc_expr
**initp, locus *var_locus)
sym->value = init;
if (sym->attr.save == SAVE_NONE)
- sym->attr.save = SAVE_IMPLICIT;
+ {
+ sym->attr.save = SAVE_IMPLICIT;
+ if (warn_surprising)
+ gfc_warning (OPT_Wsurprising, "Entity %qs at %L has an implicit "
+ "SAVE attribute", sym->name, &sym->declared_at);
+ }
*initp = NULL;
}
I see
% gfcx -o z a.f90 -Wsurprising && ./z
a.f90:2:13:
2 | integer :: i=1
| 1
Warning: Entity ‘i’ at (1) has an implicit SAVE attribute [-Wsurprising]
1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/57360] Implement a warning for implied save
2013-05-21 18:42 [Bug fortran/57360] New: Implement a warning for implied save Joost.VandeVondele at mat dot ethz.ch
` (5 preceding siblings ...)
2024-01-20 22:16 ` kargl at gcc dot gnu.org
@ 2024-01-21 17:43 ` kargl at gcc dot gnu.org
2024-01-21 17:57 ` w6ws at earthlink dot net
2024-01-23 17:17 ` w6ws at earthlink dot net
8 siblings, 0 replies; 10+ messages in thread
From: kargl at gcc dot gnu.org @ 2024-01-21 17:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57360
--- Comment #7 from kargl at gcc dot gnu.org ---
Upon some additional thinking, I wonder how useful this will be compared
to the possible volume of warning messages from modern Fortran. Consider
this code:
module foo
integer :: j = 2
type a
integer :: k = 3
end type
type(a) :: b = a(4)
integer, target :: n
integer, pointer :: m => n
end module foo
subroutine t()
integer :: i=1
write(6,*) i
i=i+1
end subroutine t
call t()
call t()
end
with the patch at the end of this email, I see
% gfcx -c -Wsurprising -Wall a.f90
a.f90:2:14:
2 | integer :: j = 2
| 1
Warning: Entity at (1) has an implicit SAVE attribute [-Wsurprising]
a.f90:6:14:
6 | type(a) :: b = a(4)
| 1
Warning: Entity at (1) has an implicit SAVE attribute [-Wsurprising]
a.f90:7:22:
7 | integer, target :: n
| 1
Warning: Entity at (1) has an implicit SAVE attribute [-Wsurprising]
a.f90:8:23:
8 | integer, pointer :: m => n
| 1
Warning: Entity at (1) has an implicit SAVE attribute [-Wsurprising]
a.f90:12:13:
12 | integer :: i=1
| 1
Warning: ‘i’ at (1) has an implicit SAVE attribute [-Wsurprising]
diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 503ecb8d9b5..d6ef37e51f2 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -2278,7 +2278,12 @@ add_init_expr_to_sym (const char *name, gfc_expr
**initp, locus *var_locus)
sym->value = init;
if (sym->attr.save == SAVE_NONE)
- sym->attr.save = SAVE_IMPLICIT;
+ {
+ sym->attr.save = SAVE_IMPLICIT;
+ if (warn_surprising)
+ gfc_warning (OPT_Wsurprising, "%qs at %L has an implicit SAVE "
+ "attribute", sym->name, &sym->declared_at);
+ }
*initp = NULL;
}
@@ -5868,7 +5873,12 @@ match_attr_spec (void)
|| gfc_current_state () == COMP_SUBMODULE)
&& !current_attr.save
&& (gfc_option.allow_std & GFC_STD_F2008) != 0)
- current_attr.save = SAVE_IMPLICIT;
+ {
+ current_attr.save = SAVE_IMPLICIT;
+ if (warn_surprising)
+ gfc_warning (OPT_Wsurprising, "Entity at %C has an implicit SAVE "
+ "attribute");
+ }
colon_seen = 1;
return MATCH_YES;
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/57360] Implement a warning for implied save
2013-05-21 18:42 [Bug fortran/57360] New: Implement a warning for implied save Joost.VandeVondele at mat dot ethz.ch
` (6 preceding siblings ...)
2024-01-21 17:43 ` kargl at gcc dot gnu.org
@ 2024-01-21 17:57 ` w6ws at earthlink dot net
2024-01-23 17:17 ` w6ws at earthlink dot net
8 siblings, 0 replies; 10+ messages in thread
From: w6ws at earthlink dot net @ 2024-01-21 17:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57360
--- Comment #8 from Walter Spector <w6ws at earthlink dot net> ---
Hi,
It is a good point. The message is helpful when issued within a procedure.
At module scope, it doesn't mean much since everything at that level is SAVE
anyway. This is similar to what happens in C:
int x = 3; // statically allocated
void fn () {
int i=3; // stack allocated
}
Walter
-----Original Message-----
From: kargl at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org>
Sent: Jan 21, 2024 9:43 AM
To: <w6ws@earthlink.net>
Subject: [Bug fortran/57360] Implement a warning for implied save
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57360
--- Comment #7 from kargl at gcc dot gnu.org ---
Upon some additional thinking, I wonder how useful this will be compared
to the possible volume of warning messages from modern Fortran. Consider
this code:
module foo
integer :: j = 2
type a
integer :: k = 3
end type
type(a) :: b = a(4)
integer, target :: n
integer, pointer :: m => n
end module foo
subroutine t()
integer :: i=1
write(6,*) i
i=i+1
end subroutine t
call t()
call t()
end
with the patch at the end of this email, I see
% gfcx -c -Wsurprising -Wall a.f90
a.f90:2:14:
2 | integer :: j = 2
| 1
Warning: Entity at (1) has an implicit SAVE attribute [-Wsurprising]
a.f90:6:14:
6 | type(a) :: b = a(4)
| 1
Warning: Entity at (1) has an implicit SAVE attribute [-Wsurprising]
a.f90:7:22:
7 | integer, target :: n
| 1
Warning: Entity at (1) has an implicit SAVE attribute [-Wsurprising]
a.f90:8:23:
8 | integer, pointer :: m => n
| 1
Warning: Entity at (1) has an implicit SAVE attribute [-Wsurprising]
a.f90:12:13:
12 | integer :: i=1
| 1
Warning: ‘i’ at (1) has an implicit SAVE attribute [-Wsurprising]
diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 503ecb8d9b5..d6ef37e51f2 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -2278,7 +2278,12 @@ add_init_expr_to_sym (const char *name, gfc_expr
**initp, locus *var_locus)
sym->value = init;
if (sym->attr.save == SAVE_NONE)
- sym->attr.save = SAVE_IMPLICIT;
+ {
+ sym->attr.save = SAVE_IMPLICIT;
+ if (warn_surprising)
+ gfc_warning (OPT_Wsurprising, "%qs at %L has an implicit SAVE "
+ "attribute", sym->name, &sym->declared_at);
+ }
*initp = NULL;
}
@@ -5868,7 +5873,12 @@ match_attr_spec (void)
|| gfc_current_state () == COMP_SUBMODULE)
&& !current_attr.save
&& (gfc_option.allow_std & GFC_STD_F2008) != 0)
- current_attr.save = SAVE_IMPLICIT;
+ {
+ current_attr.save = SAVE_IMPLICIT;
+ if (warn_surprising)
+ gfc_warning (OPT_Wsurprising, "Entity at %C has an implicit SAVE "
+ "attribute");
+ }
colon_seen = 1;
return MATCH_YES;
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/57360] Implement a warning for implied save
2013-05-21 18:42 [Bug fortran/57360] New: Implement a warning for implied save Joost.VandeVondele at mat dot ethz.ch
` (7 preceding siblings ...)
2024-01-21 17:57 ` w6ws at earthlink dot net
@ 2024-01-23 17:17 ` w6ws at earthlink dot net
8 siblings, 0 replies; 10+ messages in thread
From: w6ws at earthlink dot net @ 2024-01-23 17:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57360
--- Comment #9 from Walter Spector <w6ws at earthlink dot net> ---
It appears that Lfortran issues a message for this case. See:
https://github.com/j3-fortran/fortran_proposals/issues/83#issuecomment-1906266587
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-01-23 17:17 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-21 18:42 [Bug fortran/57360] New: Implement a warning for implied save Joost.VandeVondele at mat dot ethz.ch
2015-10-20 21:46 ` [Bug fortran/57360] " dominiq at lps dot ens.fr
2015-10-21 19:11 ` anlauf at gmx dot de
2015-10-22 5:45 ` Joost.VandeVondele at mat dot ethz.ch
2021-10-07 20:41 ` anlauf at gcc dot gnu.org
2024-01-20 18:51 ` w6ws at earthlink dot net
2024-01-20 22:16 ` kargl at gcc dot gnu.org
2024-01-21 17:43 ` kargl at gcc dot gnu.org
2024-01-21 17:57 ` w6ws at earthlink dot net
2024-01-23 17:17 ` w6ws at earthlink dot net
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).