-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #77990
- Loading branch information
Showing
3 changed files
with
50 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
! 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 |