public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/43172] Unnecessary array temporary - non-pointer/non-target does not alias
Date: Thu, 25 Feb 2010 13:21:00 -0000	[thread overview]
Message-ID: <20100225132110.1412.qmail@sourceware.org> (raw)
In-Reply-To: <bug-43172-13404@http.gcc.gnu.org/bugzilla/>



------- Comment #2 from burnus at gcc dot gnu dot org  2010-02-25 13:21 -------
(In reply to comment #1)
> In principle,
> subroutine foo (ptr, tar)
>   real, target :: tar (:,:)
>   real, pointer :: ptr (:,:)
>   ptr => tar
> end subroutine
> 
> could cause troubles in 'one' in the testcase. If I read it correctly, this is
> undefined and so processor dependent.

Without studying the standard, I had assumes that your example is valid and
well-defined (of cause assuming that the proper actual arguments are used).

Actually, I do see no closer relation to my test case in comment 0 as there
neither kpts nor syp are dummy arguments and kpts is allocatable.

 * * *

> Thus, we could cure the PR very simply
> by fixing 'gfc_symbols_could_alias' but I think that it might be a good idea
> to warn of the undefined status of the actual argument corresponding to 'ptr'

Well, I think I now slowly start to understand your point. If one does
  real :: a(4,4)
  real,pointer :: p(:,:)
  call foo(p,a)
  a = 7
  p = 0
  if (a(1,1) == 0) stop 'Aliases'
the "processor" may optimize the "stop" line away since "a" has no target
attribute and is known to be 7.  This code is invalid just because accessing
the target of "p" is invalid as "p" is has undefined association status.

However, if one slightly extends the subroutine, even the code above is valid:
  subroutine foo (ptr, tar)
    [...]
    ptr => tar
    ptr = 8
    allocate(ptr(1,1))
  end subroutine

The problem is not much different from:
 subroutine foo(p)
   integer, pointer :: p
   integer, target :: t
   p => t

which is also perfectly valid - except that after the call the actual argument
associated with "p" is a pointer with "undefined" association state. I think in
both cases one can warn with -Wsurprising, but especially your case is still
valid if the actual argument has also the TARGET attribute.

Thus, I would probably only warn with -Wsurprising for dummy_ptr =>
local_target (i.e. "local_target" is not host/use associated nor a dummy
argument) - but warning for dummy arguments is also fine with me.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43172


  parent reply	other threads:[~2010-02-25 13:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-25 11:06 [Bug fortran/43172] New: " burnus at gcc dot gnu dot org
2010-02-25 12:42 ` [Bug fortran/43172] " pault at gcc dot gnu dot org
2010-02-25 13:21 ` burnus at gcc dot gnu dot org [this message]
     [not found] <bug-43172-4@http.gcc.gnu.org/bugzilla/>
2021-12-18  1:18 ` pinskia at gcc dot gnu.org

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=20100225132110.1412.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).