public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alessandro Fanfarillo <fanfarillo.gcc@gmail.com>
To: Tobias Burnus <burnus@net-b.de>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>, gfortran <fortran@gcc.gnu.org>
Subject: Re: [PATCH, Fortran]
Date: Mon, 08 Sep 2014 22:13:00 -0000	[thread overview]
Message-ID: <CAHqFgjWUKBzXgMNujJQSyTm+jb0qd=RN1s4XLOi=S5LR0tPvkA@mail.gmail.com> (raw)
In-Reply-To: <540E2489.2030403@net-b.de>

Thanks, your suggestion fixes the problem.

I just noticed that I missed the subject description; I'll send the
new patch in a different email.

2014-09-08 15:50 GMT-06:00 Tobias Burnus <burnus@net-b.de>:
> Alessandro Fanfarillo wrote:
>
> 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.
>
>
> But I think it doesn't do the right thing if the kind is different.
>
> Suggestions?
>
>
> I think you want to do something like inserting
>
>   if (POINTER_TYPE_P (TREE_TYPE (value))
>     value = build_fold_indirect_ref_loc (input_location, value);
>
> before the assignment:
>
>  	  gfc_add_modify (&block, tmp, fold_convert (TREE_TYPE (tmp), value));
>
> otherwise you risk that you access invalid memory, e.g. for passing a
> integer(1) variable to an integer(4) atomic. On the other hand, there is
> something wrong with the check – as it shouldn't trigger when both atom and
> value have the same kind. Thus, the modified patch might work, is probably
> not completely clean either.
>
> Tobias
>
> 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 ----

  parent reply	other threads:[~2014-09-08 22:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-08 21:23 Alessandro Fanfarillo
     [not found] ` <540E2489.2030403@net-b.de>
2014-09-08 22:13   ` Alessandro Fanfarillo [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-07-14 17:47 [patch, fortran] Jerry DeLisle
2014-04-08 12:04 [PATCH, FORTRAN] Bernd Edlinger
2011-06-05 21:00 [patch, fortran] Thomas Koenig
2006-06-23 17:16 [Patch, fortran] Paul Thomas
2006-06-24 15:35 ` Steve Kargl
2006-06-25  7:09   ` Paul Thomas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHqFgjWUKBzXgMNujJQSyTm+jb0qd=RN1s4XLOi=S5LR0tPvkA@mail.gmail.com' \
    --to=fanfarillo.gcc@gmail.com \
    --cc=burnus@net-b.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).