Files
clang-p2996/flang/test/Semantics/execute_command_line.f90
Yi Wu 14a15103cc Apply kind code check on exitstat and cmdstat (#78286)
When testing on gcc, both exitstat and cmdstat must be a kind=4 integer,
e.g. DefaultInt. This patch changes the input arg requirement from
`AnyInt` to `TypePattern{IntType, KindCode::greaterOrEqualToKind, n}`.

The standard stated in 16.9.73
- EXITSTAT (optional) shall be a scalar of type integer with a decimal
exponent range of at least nine.
- CMDSTAT (optional) shall be a scalar of type integer with a decimal
exponent range of at least four.
 
```fortran
program bug
  implicit none
  integer(kind = 2) :: exitstatvar
  integer(kind = 4) :: cmdstatvar 
  character(len=256) :: msg
  character(len=:), allocatable :: command
  command='echo hello'
  call execute_command_line(command, exitstat=exitstatvar, cmdstat=cmdstatvar)
end program
```
When testing the above program with exitstatvar kind<4, an error would
occur:
```
$ ../build-release/bin/flang-new test.f90 
error: Semantic errors in test.f90
./test.f90:8:47: error: Actual argument for 'exitstat=' has bad type or kind 'INTEGER(2)'
    call execute_command_line(command, exitstat=exitstatvar)
```

When testing the above program with exitstatvar kind<2, an error would
occur:
```
$ ../build-release/bin/flang-new test.f90 
error: Semantic errors in test.f90
./test.f90:8:47: error: Actual argument for 'cmdstat=' has bad type or kind 'INTEGER(1)'
    call execute_command_line(command, cmdstat=cmdstatvar)
```

Test file for this semantics has been added to `flang/test/Semantic`
Fixes: https://github.com/llvm/llvm-project/issues/77990
2024-01-29 11:13:25 +00:00

30 lines
1.0 KiB
Fortran

! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
! Tests for the EXECUTE_COMMAND_LINE intrinsics
subroutine bad_kind_error(command, exitVal, cmdVal)
CHARACTER(30) :: command
INTEGER(KIND=2) :: exitVal
INTEGER(KIND=1) :: cmdVal
!ERROR: Actual argument for 'exitstat=' has bad type or kind 'INTEGER(2)'
call execute_command_line(command, exitstat=exitVal)
!ERROR: Actual argument for 'cmdstat=' has bad type or kind 'INTEGER(1)'
call execute_command_line(command, cmdstat=cmdVal)
end subroutine bad_kind_error
subroutine good_kind_equal(command, exitVal, cmdVal)
CHARACTER(30) :: command
INTEGER(KIND=4) :: exitVal
INTEGER(KIND=2) :: cmdVal
call execute_command_line(command, exitstat=exitVal)
call execute_command_line(command, cmdstat=cmdVal)
end subroutine good_kind_equal
subroutine good_kind_greater(command, exitVal, cmdVal)
CHARACTER(30) :: command
INTEGER(KIND=8) :: exitVal
INTEGER(KIND=4) :: cmdVal
call execute_command_line(command, exitstat=exitVal)
call execute_command_line(command, cmdstat=cmdVal)
end subroutine good_kind_greater