| Issue |
115012
|
| Summary |
[flang] `c_f_pointer` erroneous warning
|
| Labels |
flang
|
| Assignees |
|
| Reporter |
everythingfunctional
|
When compiling something like the following code:
```fortran
program main
use iso_c_binding
implicit none
type :: a
integer, pointer :: b
end type
type(a), target :: c
type(a), pointer :: d
call c_f_pointer(cptr = c_loc(c), fptr = d)
end program
```
flang reports an error like the following:
```text
./example.f90:13:46: warning: FPTR= argument to C_F_POINTER() should not have a derived type that is not BIND(C)
call c_f_pointer(cptr = c_loc(c), fptr = d)
```
However the standard does not make this requirement, i.e.
> 18.2.3.3 C_F_POINTER (CPTR, FPTR [, SHAPE, LOWER])
> ...
> CPTR shall be a scalar of type C_PTR ... Its value shall be
> ...
> * the result of a reference to C_LOC with a noninteroperable argument
> ...
> FPTR shall be a pointer, shall not have a deferred type parameter, and shall not be a coindexed object. ...
In fact, an example in the standard makes clear that this use case is valid
```fortran
Type t
Real, Allocatable :: v(:,:)
End Type
Type(t), Target :: x(0:2)
Type(C_ptr) :: xloc
xloc = C_Loc (x)
...
Type(t), Pointer :: y(:)
Call C_F_Pointer (xloc, y, [3], [0])
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs