IV49616: INCORRECT OUTPUT WITH C_LOC() C_PTR ALLOCATABLE POINTER

Subscribe

You can track all active APARs for this component.

APAR status

  • Closed as program error.

Error description

  • The following test case should produce same outputs for each
    referenced memory address. But if the following condition
    meets, the last call references a different memory address.
    
    a) The variable x is of a derived type which contains
    components that have the attribute 'allocatable'.
    b) The value returned by c_loc(x) is used directly (without
    being saved in a variable) as an actual argument to a C
    function (or subroutine) with a Fortran interface.
    
    -bash-4.1$ cat a.f90
    module c
      type :: t1
        integer :: i
      end type
    
      type :: t2
        integer, allocatable :: i   !!===> this fails!!
    !    integer, pointer :: i      !!===> this works around!!
      end type
    end module
    
    program a
      use, intrinsic :: iso_c_binding
      use b
      use c
      implicit none
    
      type(c_ptr) :: p1, p2
      type(t1), target :: x1
      type(t2), target :: x2
    
      print *, "Using t1 (without allocatable component):"
      call s(x1)
      p1 = c_loc(x1)
      call s_f(p1)
      call s_f(c_loc(x1))
    
      print *, "Using t2 (with allocatable component):"
      call s(x2)
      p2 = c_loc(x2)
      call s_f(p2)
      call s_f(c_loc(x2))    !!====> incorrect output for this call
    end program
    
    -bash-4.1$ cat b_f.f90
    module b
      implicit none
    
      interface
        subroutine s_f(p) bind(C, name='s_f')
          use, intrinsic :: iso_c_binding
          implicit none
          type(c_ptr), intent(in), value :: p
        end subroutine
      end interface
    end module
    
    
    -bash-4.1$ cat b_c.c
    #include <stdio.h>
    
    void s_f(void* p) {
      printf("%p\n", p);
    }
    
    void s(void *p) {
      printf("%p\n", p);
    }
    
    #!/bin/sh
    
    export CC=xlc_r
    exportFC=xlf2008_r
    
    $CC -c b_c.c
    $FC -c b_f.f90
    $FC -c a.f90
    $FC -o a b_c.o b_f.o a.o
    
    ===== ACTUAL OUTPUT:
    -bash-4.1$ ./a
     Using t1 (without allocatable component):
    0xfff843c8
    0xfff843c8
    0xfff843c8
     Using t2 (with allocatable component):
    0xfff843b8
    0xfff843b8
    0xfff843dc   ========> different address for the last call
    
    
    ===== EXPECTED OUTPUT:
    Same addresses, such as:
    
    -bash-4.1$ ./a
     Using t1 (without allocatable component):
    0xfff9de98
    0xfff9de98
    0xfff9de98
     Using t2 (with allocatable component):
    0xfff9de88
    0xfff9de88
    0xfff9de88
    

Local fix

  • Change
      type :: t2
        integer, allocatable :: i
      end type
    To
      type :: t2
        integer, pointer :: i
      end type
    

Problem summary

  • PROBLEM DESCRIPTION: When the result of C_LOC is passed by
    value to a procedure, the compiler may pass incorect value to
    the callee resulting in functional failure.
    
    USERS AFFECTED: Users of applications that pass result of C_LOC
    by value to a procedure may experience this problem.
    

Problem conclusion

  • The problem has been fixed.
    Apply provided service.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IV49616

  • Reported component name

    XL FORTRAN FOR

  • Reported component ID

    5725C7400

  • Reported release

    E10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2013-09-18

  • Closed date

    2013-09-18

  • Last modified date

    2013-09-20

  • APAR is sysrouted FROM one or more of the following:

    LI77271

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    XL FORTRAN FOR

  • Fixed component ID

    5725C7400

Applicable component levels

  • RE10 PSN U861038

       UP06/09/13 C



Rate this page:

(0 users)Average rating

Document information


More support for:

XL Fortran for AIX
Compiler

Software version:

14.1

Reference #:

IV49616

Modified date:

2013-09-20

Translate my page

Machine Translation

Content navigation