Permalink
Browse files

Fix issue with VALUE attribute and BIND(C) routine

Passing by reference was used instead of passing by value.
  • Loading branch information...
gklimowicz committed Feb 6, 2019
1 parent 91e8f33 commit 604bad4101562aeaf033cb3cc2c86d04cd5cf8fd
Showing with 1 addition and 1 deletion.
  1. +1 −1 tools/flang1/flang1exe/semfunc.c
@@ -523,7 +523,7 @@ byvalue_ref_arg(SST *e1, int *dtype, int op, int func_sptr)

saved_dtype = A_DTYPEG(SST_ASTG(e1));

if ((A_TYPEG(SST_ASTG(e1)) == A_FUNC) && (is_iso_cptr(saved_dtype))) {
if ((A_TYPEG(SST_ASTG(e1)) == A_FUNC) && (is_iso_cptr(saved_dtype)) && !CFUNCG(func_sptr)) {
/* functions returning c_ptr structs become funcs
returning ints, so that we simply copy the
(integer)pointer

3 comments on commit 604bad4

@pawosm-arm

This comment has been minimized.

Copy link
Contributor

pawosm-arm replied Feb 7, 2019

I've cherry-picked this one and the bug with VALUE attributed parameter still occurs. Following code:

module my_c_ptr

  use, intrinsic :: ISO_C_BINDING
   implicit none

contains

  function my_function(i) result(ptr) bind(C)
     integer(C_INT), value, intent(in) :: i
     type(C_PTR) :: ptr
     ptr = C_NULL_PTR
  end function
end module

...causes following ICE:

/tmp/ptr_bug_lite-25d9df.ll:28: error: value doesn't match function result type 'i64'
        ret i8* %5

1 error generated.

Removal of 'VALUE' makes this code able to be compiled.

@gklimowicz

This comment has been minimized.

Copy link
Contributor Author

gklimowicz replied Feb 7, 2019

This appears to be a separate issue, which we will put in the queue to look at.

@pawosm-arm

This comment has been minimized.

Copy link
Contributor

pawosm-arm replied Feb 9, 2019

A new ticket opened, #669.

Please sign in to comment.