llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[flang] All STAT= specifier should be an integer that's at least 16-bit.

Open JDPailleux opened this issue 1 month ago • 5 comments

In the PR#230031, @bonachea mentionned this behavior that flang doesn't follow:

F2023 9.7.4 also says (same in F2018):

R946 stat-variable is scalar-int-variable

A stat-variable should have a decimal exponent range of at least four; otherwise the processor-dependent error code might not be representable in the variable.

In plain English, the implication is the standard requires the argument to STAT to be an integer that's at least 16-bit.

But flang currently silently accepts 8-bit integers to STAT=:

cgpu$ cat stat2.F90 
program stat_test
use iso_c_binding
integer :: coarray[*]
integer(C_INT8_T) :: myint8
integer(C_INT16_T) :: myint16

coarray[1, stat=myint8] = 0 ! violates F2023 9.7.4

coarray[1, stat=myint16] = 0 ! ok

end program

cgpu$ flang -fsyntax-only stat2.F90

JDPailleux avatar Oct 09 '26 11:10 JDPailleux

I'm on it

JDPailleux avatar Oct 09 '26 11:10 JDPailleux

What do the other compilers do? Maybe it should be '-pedantic' warning?

eugeneepshteyn avatar Oct 09 '26 12:10 eugeneepshteyn

@eugeneepshteyn gfortran doesn't throw an error and accepts this. So I suppose adding an error might break a lot of existing code. I think it's actually best to treat this as a '-pedantic' warning

JDPailleux avatar Oct 09 '26 13:10 JDPailleux

Yeah, I was thinking that the user may know something about the runtime codes and may have a good reason to use 8 bit variable. Having -pedantic warning would be valuable to catch mistakes.

eugeneepshteyn avatar Oct 09 '26 13:10 eugeneepshteyn

Oh, since flang will only warn at -pedantic, it probably needs a sentence description in Extensions.md.

eugeneepshteyn avatar Oct 09 '26 13:10 eugeneepshteyn