Dear all,

the following code produces a wrong invocation to libcaf for
caf_atomic_op (atomic_add):

program atomic
use iso_fortran_env
implicit none

integer :: me
integer(atomic_int_kind) :: atom[*]
me = this_image()
call atomic_define(atom[1],0)
sync all
call ATOMIC_ADD (atom[1], me)
if(me == 1) call atomic_ref(me,atom[1])
sync all
write(*,*) me

end program

The compiler translates the caf_atomic_op call (related with atomic_add) as:

    integer(kind=4) value.3;

    value.3 = (integer(kind=4)) &me;
    _gfortran_caf_atomic_op (1, caf_token.0, 0, 1, &value.3, 0B, 0B, 1, 4);

The attached patch seems to fix the problem.


Suggestions?
Index: gcc/fortran/trans-intrinsic.c
===================================================================
*** gcc/fortran/trans-intrinsic.c       (revision 215016)
--- gcc/fortran/trans-intrinsic.c       (working copy)
*************** conv_intrinsic_atomic_op (gfc_code *code
*** 8396,8408 ****
        else
        image_index = integer_zero_node;
  
-       if (TREE_TYPE (TREE_TYPE (atom)) != TREE_TYPE (TREE_TYPE (value)))
-       {
-         tmp = gfc_create_var (TREE_TYPE (TREE_TYPE (atom)), "value");
-         gfc_add_modify (&block, tmp, fold_convert (TREE_TYPE (tmp), value));
-           value = gfc_build_addr_expr (NULL_TREE, tmp);
-       }
- 
        gfc_get_caf_token_offset (&token, &offset, caf_decl, atom, atom_expr);
  
        if (code->resolved_isym->id == GFC_ISYM_ATOMIC_DEF)
--- 8396,8401 ----

Reply via email to