[Bug fortran/90536] Spurious (?) warning when using -Wconversion with -fno-range-check
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90536 Thomas Koenig changed: What|Removed |Added Assignee|tkoenig at gcc dot gnu.org |unassigned at gcc dot gnu.org Status|ASSIGNED|NEW
[Bug fortran/90536] Spurious (?) warning when using -Wconversion with -fno-range-check
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90536 --- Comment #14 from Steve Kargl --- On Wed, May 22, 2019 at 11:21:52PM +, j.ravens.nz at gmail dot com wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90536 > > --- Comment #13 from Jonathan Ravens --- > Thanks everyone for your input on this issue. I hadn't realised thati > it could cause such dissent. There is no dissent. > As a software developer, my major driver is to manage the users' > expectations. > In that respect, declaring a byte and being able to set it to a valid value > should not raise a warning, especially when an option called no-range-check is > in use which, intuitively, would suppress range-checking errors instead of > causing them. I suggest it might only be technically correct from a > developer's perspective, but not from the user's. You appear to be conflating 2 issues. Range checking has nothing to do with type conversion. In your original code, you have a BOZ of '89'X (which to be standard conforming should be written as Z'89'). This BOZ is either an INTEGER(8) or INTEGER(16) (depends on the target) because gfortran follows how Fortran 95 handles a BOZ in a DATA statement (the only place a BOZ can appear in valid Fortran 95 code). It has a value of 137. So, you now have 2 problems when you are trying to assign it to a BYTE (aka INTEGER(1)) entity: 1) It is out-of-range. 2) It has a type of INTEGER(8) or INTEGER(16). -fno-range-check takes care of 1). -Wno-conversion takes care or 2). Now, when you have '09'X (or correctly Z'09'), this BOZ has a value of 9, but it is still a INTEGER(8) or INTEGER(16) entity. When gfortran performs the ranging checking for assigning 9 to a BYTE (aka INTEGER(1)) entity, it inibits the conversion warning because 9 is in range of a BYTE (aka INTEGER(1)). A warning isn't needed because gfortran knows there is no problem. When you specify -Wall -fno-range-check, the only thing that gfortran knows is that you're assigning an INTEGER(8) or INTEGER(16) entity to a BYTE (aka INTEGER(1)). So, gfortran brings the potential problem to your attention. You specifically requested this behavior via the options! > If commonly-used constructs such as BYTE are to be removed from gfortran, I'd > expect that to require a lot of re-coding for people in general, given the > amount of legacy Fortran code in use. In our case, I think the best option > would be to phase out usage of gfortran. No decisions have been made. I'll raise an RFC about deprecation of a number of mistakes in gfortran (when time permits as I am not paid to contribute to gfortran). The plan would be to issue a deprecation notice in the 10.x releases of gfortran with removal of the mistakes in 11.1. A deprection notice cannot be suppressed by an option, so user will see the notice everytime the user compiles his/her code. So, removal won't happen for 2 or more years. If removal of a mistake such as BYTE causes you to stop using gfortran, oh well.
[Bug fortran/90536] Spurious (?) warning when using -Wconversion with -fno-range-check
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90536 --- Comment #13 from Jonathan Ravens --- Thanks everyone for your input on this issue. I hadn't realised that it could cause such dissent. As a software developer, my major driver is to manage the users' expectations. In that respect, declaring a byte and being able to set it to a valid value should not raise a warning, especially when an option called no-range-check is in use which, intuitively, would suppress range-checking errors instead of causing them. I suggest it might only be technically correct from a developer's perspective, but not from the user's. If commonly-used constructs such as BYTE are to be removed from gfortran, I'd expect that to require a lot of re-coding for people in general, given the amount of legacy Fortran code in use. In our case, I think the best option would be to phase out usage of gfortran.
[Bug fortran/90536] Spurious (?) warning when using -Wconversion with -fno-range-check
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90536 --- Comment #12 from Steve Kargl --- On Mon, May 20, 2019 at 03:06:32PM +, sgk at troutmask dot apl.washington.edu wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90536 > > --- Comment #11 from Steve Kargl --- > On Mon, May 20, 2019 at 07:32:09AM +, tkoenig at gcc dot gnu.org wrote: > > > > what I meant is that > > > > Program main > > Integer(kind=1) :: n > > n = 1 > > End > > > > should not warn with -fno-range-check -Wall, and it does. > > > > The warning technically is correct. It is a warning about the > type conversion not about the value. > Upon further reflection, not only is gfortran's behavior correct, it is desireable. This PR should be closed as INVALID. Why? For the above code, neither gfortran -c -Wconversion a.f90 nor gfortran -c -Wconversion-extra a.f90 emit a warning because gfortran does range checking, determines that the INTEGER(4) '1' on the RHS is within range of an INTEGER(1) 'n' on the LHS when type conversion is done, and so chooses to suppress a conversion warning. When a user uses -fno-range-check, she/he is specifically asking the compiler to not range check. gfortran only knows that the RHS is an INTEGER(1) entity and the LHS is an INTEGER(4) entity. It has no other information upon which to make a decision of whether to emit a warning. So, gfortran informs the user that a conversion occurs. There is no other information without range checking.
[Bug fortran/90536] Spurious (?) warning when using -Wconversion with -fno-range-check
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90536 Thomas Koenig changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |tkoenig at gcc dot gnu.org
[Bug fortran/90536] Spurious (?) warning when using -Wconversion with -fno-range-check
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90536 --- Comment #11 from Steve Kargl --- On Mon, May 20, 2019 at 07:32:09AM +, tkoenig at gcc dot gnu.org wrote: > > what I meant is that > > Program main > Integer(kind=1) :: n > n = 1 > End > > should not warn with -fno-range-check -Wall, and it does. > The warning technically is correct. It is a warning about the type conversion not about the value. d.f90:3:6: 3 | n = 1 | 1 Warning: Conversion from 'INTEGER(4)' to 'INTEGER(1)' at (1) [-Wconversion] Here '1' is INTEGER(4). The assignment converts it to INTEGER(1). Hence, a warning is issued. Preventing range checking causes one to take a different path through the compiler. If -Wconversion is active, then you shockingly might get a warning. If a user doesn't want to see warnings, don't ask for them! In fact, one might argument that if a warning isn't issued with either -Wconversion or especially -Wconversion-extra, then these options are broken. Personally, I think this PR is much ado about nothing as one can simply add -Wno-conversion to the options to suppress a valid warning. I closed the PR. It has now been re-opened, but mysteriously it has not be assigned.
[Bug fortran/90536] Spurious (?) warning when using -Wconversion with -fno-range-check
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90536 Dominique d'Humieres changed: What|Removed |Added Summary|Use of -fno-range-check |Spurious (?) warning when |creates warnings or errors |using -Wconversion with |when assigning to a byte|-fno-range-check |variable| --- Comment #10 from Dominique d'Humieres --- The following test program test integer :: b1 = 2_8 end gives no warning when compiled with -Wconversion -Wconversion-extra: % gfc pr90536_1_db.f90 -Wconversion -Wconversion-extra % but a warning when compiled with -Wconversion -fno-range-check: % gfc pr90536_1_db.f90 -Wconversion -fno-range-check pr90536_1_db.f90:2:23: 2 | integer :: b1 = 2_8 | 1 Warning: Conversion from 'INTEGER(8)' to 'INTEGER(4)' at (1) [-Wconversion] I see in fortran/intrinsic.c /* Do nothing. Constants of the same type are range-checked elsewhere. If a value too large for the target type is assigned, an error is generated. Not checking here avoids duplications of warnings/errors. If range checking was disabled, but -Wconversion enabled, a non range checked warning is generated below. */ So the behavior may be intended.