Re: porting-to update request

2025-03-25 Thread Steve Kargl
TL;DR version: fix your code.


On Tue, Mar 25, 2025 at 11:04:52AM -0400, NightStrike wrote:
> Between GCC 9 and 10, the following code now errors out:
> 

Did you read the Release Notes for 10.1?  Under the Fortran header:

The handling of a BOZ literal constant has been reworked to provide
better conformance to the Fortran 2008 and 2018 standards.  In these
Fortran standards, a BOZ literal constant is a typeless and kindless
entity.  As a part of the rework, documented and undocumented
extensions to the Fortran standard now emit errors during compilation.
Some of these extensions are permitted with the -fallow-invalid-boz
option, which degrades the error to a warning and the code is compiled
as with older gfortran. 

Note the use of "Some of these extensions ..."

> integer function fcn(x)
>   implicit none
>   integer, intent(in) :: x
>   fcn = x * '0100'X
> end function fcn
> 
> Error: BOZ constant at (1) uses nonstandard postfix syntax [see
> '-fno-allow-invalid-boz']
> Compiler returned: 1
> 
> First, the error message is wrong regarding the option to go see:
> 
> gfortran: error: unrecognized command-line option
> '-fno-allow-invalid-boz'; did you mean '-fallow-invalid-boz'?

Your 3-character patch is pre-approve for committing. 

Did you simply copuy-n-paste the option from the error message,
or did you actually read the documentation for the option?

‘-fallow-invalid-boz’
 A BOZ literal constant can occur in a limited number of contexts in
 standard conforming Fortran.  This option degrades an error
 condition to a warning, and allows a BOZ literal constant to appear
 where the Fortran standard would otherwise prohibit its use.

Feel free to update the manual to state that "allows a BOZ literal
constant to appear ***in some locations*** where the Fortran standard
would otherwise prohibit its use.

> Second, that option doesn't protect against the aforementioned case.

This statement makes no sense.  The option degrades an error
to a warning.

% gfcx -c a.f90
a.f90:4:19:

4 |   fcn = x * '0100'X
  |   1
Error: BOZ constant at (1) uses nonstandard postfix syntax
 [see '-fno-allow-invalid-boz']


gfcx -c -fallow-invalid-boz a.f90
a.f90:4:19:

4 |   fcn = x * '0100'X
  |   1
Warning: BOZ constant at (1) uses nonstandard postfix syntax

You now the error message,


a.f90:4:8:

4 |   fcn = x * '0100'X
  |1
Error: Operands of binary numeric operator '*' at (1) are INTEGER(4)/BOZ

which is the desired behavior as a BOZ is typeless and kindless.

> Third, and the main point of this email I guess, is that the
> porting-to page should mention this:
> https://www.gnu.org/software/gcc/gcc-10/porting_to.html

It's in the Release Notes.  Feel free write whatever porting
text you want.

Did you read section 5.1.0 of the gfortran manual?


If you got this far, "FIX YOUR CODE" or revert back
to GCC 9. 


-- 
Steve


Re: [GSoC]Fortran – run-time argument checking

2025-03-25 Thread Steve Kargl
On Tue, Mar 25, 2025 at 08:34:51PM +0800, Gwen Fu wrote:
> I found out that "-fcheck=*" is an option for runtime checking, but the
> relevant options are commented out.
>   OPT_fcheck_ = 1070,/* -fcheck= */
>   /* OPT_fcheck_assert = 1071, *//* -fcheck=assert */
>   /* OPT_fcheck_bounds = 1072, *//* -fcheck=bounds */
>   /* OPT_fcheck_in = 1073, *//* -fcheck=in */
>   /* OPT_fcheck_invariant = 1074, */ /* -fcheck=invariant */
>   /* OPT_fcheck_out = 1075, */   /* -fcheck=out */
>   /* OPT_fcheck_switch = 1076, *//* -fcheck=switch */
>   OPT_fcheckaction_ = 1077,  /* -fcheckaction= */
>   OPT_fchecking = 1078,  /* -fchecking */
> 
> And I tried :
> $ gfortran -o fibonacci fabonaqi.f90 -fcheck=in
> f951: Warning: command-line option ‘-fpreconditions’ is valid for D but not
> for Fortran
> $ gfortran --help=check
> cc1: warning: unrecognized argument to ‘--help=’ option: ‘check’
> So what's wrong with these ?

Those options do not apply to gfortran, e.g.,

% find gcc/fortran -type f | xargs grep -i fcheck_invariant
% find libgfortran -type f | xargs grep -i fcheck_invariant

The gfortran manual tells you which keywords are supported:

 -fcheck=

-- 
Steve


porting-to update request

2025-03-25 Thread NightStrike
Between GCC 9 and 10, the following code now errors out:

integer function fcn(x)
  implicit none
  integer, intent(in) :: x
  fcn = x * '0100'X
end function fcn

Error: BOZ constant at (1) uses nonstandard postfix syntax [see
'-fno-allow-invalid-boz']
Compiler returned: 1

First, the error message is wrong regarding the option to go see:

gfortran: error: unrecognized command-line option
'-fno-allow-invalid-boz'; did you mean '-fallow-invalid-boz'?

Second, that option doesn't protect against the aforementioned case.

Third, and the main point of this email I guess, is that the
porting-to page should mention this:
https://www.gnu.org/software/gcc/gcc-10/porting_to.html

It talks about argument mismatches, but it doesn't talk about BOZ
literals in expressions, which used to be (perhaps incorrectly)
accepted.  There is no new command line option to accept this legacy
code, so the webpage should be updated at a minimum.


[GSoC]Fortran – run-time argument checking

2025-03-25 Thread Gwen Fu
I found out that "-fcheck=*" is an option for runtime checking, but the
relevant options are commented out.
  OPT_fcheck_ = 1070,/* -fcheck= */
  /* OPT_fcheck_assert = 1071, *//* -fcheck=assert */
  /* OPT_fcheck_bounds = 1072, *//* -fcheck=bounds */
  /* OPT_fcheck_in = 1073, *//* -fcheck=in */
  /* OPT_fcheck_invariant = 1074, */ /* -fcheck=invariant */
  /* OPT_fcheck_out = 1075, */   /* -fcheck=out */
  /* OPT_fcheck_switch = 1076, *//* -fcheck=switch */
  OPT_fcheckaction_ = 1077,  /* -fcheckaction= */
  OPT_fchecking = 1078,  /* -fchecking */

And I tried :
$ gfortran -o fibonacci fabonaqi.f90 -fcheck=in
f951: Warning: command-line option ‘-fpreconditions’ is valid for D but not
for Fortran
$ gfortran --help=check
cc1: warning: unrecognized argument to ‘--help=’ option: ‘check’
So what's wrong with these ?