Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28518 Discussions

Problem with C_F_POINTER and the LOWER argument

Robert_van_Amerongen
New Contributor III
505 Views

In the most recent compiler the C_F_POINTER function accepts the LOWER argument . I have used it, but I see that someting is wrong. The shape of the result is not equal to the shape as it was supplied when calling the function. I add a small example. Is this a compiler bug or do I miss something?

Robert

5 Replies
FortranFan
Honored Contributor II
477 Views

It is a bug.

Intel Support team, this might be an issue with a naive implementation of the latest Fortran 2023 feature without any validation checking.  It appears the upper bound of the result pointer that shall be an object defined by means of a Fortran processor gets set to -1 by Intel Fortran when lower bound is specified. Perhaps the Intel Fortran team will be interested in using another test case below?

   use, intrinsic :: iso_c_binding, only : c_loc, c_f_pointer
   blk1: block
      character(len=:), allocatable, target :: x(:)
      character(len=:), pointer :: y(:)
      print *, "Block 1: intrinsic type character"
      x = [ character(len=4) :: "How", "are", "you?" ]
      call c_f_pointer( cptr=c_loc(x), fptr=y, shape=shape(x), lower=[ -1 ] )
      print *, "lbound(y): ", lbound(y, dim=1), "; expected is -1"
      print *, "ubound(y): ", ubound(y, dim=1), "; expected is 1"
      print *, "y = ", y
   end block blk1
   print *
   blk2: block
      integer, target :: x(5)
      integer, pointer :: y(:)
      print *, "Block 2: intrinsic type integer"
      x = [ 1, 2, 3, 4, 5 ]
      call c_f_pointer( cptr=c_loc(x), fptr=y, shape=shape(x), lower=[ -2 ] )
      print *, "lbound(y): ", lbound(y, dim=1), "; expected is -2"
      print *, "ubound(y): ", ubound(y, dim=1), "; expected is 2"
      print *, "y = ", y
   end block blk2
   print *
   blk3: block
      real, target :: x(7)
      real, pointer :: y(:)
      print *, "Block 3: intrinsic type real"
      x = [( real(i), integer :: i = 1, size(x) )]
      call c_f_pointer( cptr=c_loc(x), fptr=y, shape=shape(x), lower=[ -3 ] )
      print *, "lbound(y): ", lbound(y, dim=1), "; expected is -3"
      print *, "ubound(y): ", ubound(y, dim=1), "; expected is 3"
      print *, "y = ", y
   end block blk3
end
C:\Temp>ifx /standard-semantics /free p.f
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.1.0 Build 20240308
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.36.32537.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:p.exe
-subsystem:console
p.obj

C:\Temp>p.exe
 Block 1: intrinsic type character
 lbound(y):  -1 ; expected is -1
 ubound(y):  -1 ; expected is 1
 y =

 Block 2: intrinsic type integer
 lbound(y):  -2 ; expected is -2
 ubound(y):  -1 ; expected is 2
 y =  1 2

 Block 3: intrinsic type real
 lbound(y):  -3 ; expected is -3
 ubound(y):  -1 ; expected is 3
 y =  1.000000 2.000000 3.000000

 

Barbara_P_Intel
Employee
397 Views

Thank you for reporting this,@Robert_van_Amerongen. Thanks, too, for the small reproducer.

Thank you, @FortranFan, for another reproducer! The Fortran compiler engineers appreciate that!

I file a bug report, CMPLRLLVM-57611, and included both reproducers. We'll let you know its progress to a fix.

 

 

0 Kudos
Robert_van_Amerongen
New Contributor III
383 Views

Barbara and FortranFan,

thanks for your help.

Robert

0 Kudos
Barbara_P_Intel
Employee
261 Views

Good news! The Fortran compiler team got right on this! Look for the fix in the 2024.2 release planned for mid-2024.



0 Kudos
Robert_van_Amerongen
New Contributor III
238 Views

That is nice to read.

Tanks to te team.

And for you to let me know.

Robert

0 Kudos
Reply