Files
TheRock/compiler/amd-llvm/flang/test/Semantics/c_f_strpointer.f90
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

75 lines
3.0 KiB
Fortran

! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
! Enforce C_F_STRPOINTER semantics (18.2.3.5)
program test
use iso_c_binding
type(c_ptr) :: cptr
character(len=:), pointer :: fstrptr
character(len=1, kind=c_char), dimension(100), target :: cstrarray
character(len=10), pointer :: fstrptr_not_deferred
integer :: nchars
! Valid calls
call c_f_strpointer(cstrarray, fstrptr) ! ok
call c_f_strpointer(cstrarray, fstrptr, 50) ! ok with NCHARS
call c_f_strpointer(cptr, fstrptr, 100) ! ok with CSTRPTR form
call c_f_strpointer(CSTRARRAY=cstrarray, FSTRPTR=fstrptr) ! ok with CSTRARRAY keyword
call c_f_strpointer(CSTRARRAY=cstrarray, FSTRPTR=fstrptr, NCHARS=50) ! ok with all keywords
call c_f_strpointer(CSTRPTR=cptr, FSTRPTR=fstrptr, NCHARS=50) ! ok with all keywords
! Error: CSTRPTR form requires NCHARS
!ERROR: NCHARS= argument is required when CSTRPTR= appears in C_F_STRPOINTER()
call c_f_strpointer(cptr, fstrptr)
! Error: CSTRPTR form requires NCHARS (with explicit keyword)
!ERROR: NCHARS= argument is required when CSTRPTR= appears in C_F_STRPOINTER()
call c_f_strpointer(CSTRPTR=cptr, FSTRPTR=fstrptr)
! Error: Wrong keyword for C_PTR argument
!ERROR: Keyword CSTRARRAY= cannot be used with a C_PTR argument; use CSTRPTR= instead
call c_f_strpointer(CSTRARRAY=cptr, FSTRPTR=fstrptr, NCHARS=10)
! Error: Wrong keyword for character array argument
!ERROR: Keyword CSTRPTR= cannot be used with a character array argument; use CSTRARRAY= instead
call c_f_strpointer(CSTRPTR=cstrarray, FSTRPTR=fstrptr, NCHARS=50)
! Error: FSTRPTR must have deferred length
!ERROR: FSTRPTR= argument to C_F_STRPOINTER() must have deferred length
call c_f_strpointer(cstrarray, fstrptr_not_deferred)
! Error: NCHARS must be non-negative
!ERROR: NCHARS= argument to C_F_STRPOINTER() must be non-negative
call c_f_strpointer(cstrarray, fstrptr, -5)
! Error: NCHARS greater than array size (compile-time check)
!ERROR: NCHARS=150 is greater than the size of CSTRARRAY=100 in C_F_STRPOINTER()
call c_f_strpointer(cstrarray, fstrptr, 150)
! Error: Missing required argument FSTRPTR
!ERROR: Dummy argument 'fstrptr=' is absent and not OPTIONAL
call c_f_strpointer(cstrarray)
! Error: Missing both required arguments
!ERROR: Dummy argument 'cstr=' is absent and not OPTIONAL
!ERROR: Dummy argument 'fstrptr=' is absent and not OPTIONAL
call c_f_strpointer()
! Error: Too many arguments
!ERROR: Too many actual arguments (4 > 3)
call c_f_strpointer(cstrarray, fstrptr, 50, 999)
end program
subroutine test_assumed_size(cstrarray_assumed, fstrptr)
use iso_c_binding
character(len=1, kind=c_char), dimension(*), target, intent(in) :: cstrarray_assumed
character(len=:), pointer :: fstrptr
! Error: Assumed-size requires NCHARS
!ERROR: NCHARS= argument is required when CSTRARRAY= is assumed-size in C_F_STRPOINTER()
call c_f_strpointer(cstrarray_assumed, fstrptr)
! Valid: Assumed-size with NCHARS
call c_f_strpointer(cstrarray_assumed, fstrptr, 100)
end subroutine