public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sgk at troutmask dot apl.washington.edu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/51208] [OOP] ALLOCATE with SOURCE= or MOLD=: Diagnose if variable occurs twice
Date: Fri, 18 Nov 2011 19:03:00 -0000 [thread overview]
Message-ID: <bug-51208-4-lztv6ATEc0@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-51208-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51208
--- Comment #3 from Steve Kargl <sgk at troutmask dot apl.washington.edu> 2011-11-18 18:40:31 UTC ---
On Fri, Nov 18, 2011 at 04:03:04PM +0000, burnus at gcc dot gnu.org wrote:
>
> Well, it is not. One can restrict one to the common case of expr->expr_type ==
> EXPR_VARIABLE and just do the same as for STAT=: Checking whether the variable
> is the same.
>
> Will that catch all wrong usage? No, but it will catch the most common mistake
> of choosing the wrong variable. That's as illustrated above the same with
> STAT=.
>
> I am sure that Intel's compiler does not do anything more advanced - and it
> would have found the mistake I made in PR 51207.
>
Although I think this is equilavent to putting a bandaid
on a AK-47 bullet hole, here you go
troutmask:sgk[246] cat foo.f90
program foo
use bar
allocate(x(2), source=x)
end program foo
troutmask:sgk[245] gfc4x -o z -Wall -Wextra foo.f90
foo.f90:4.11-24:
allocate(x(2), source=x)
1 2
Error: Allocate-object at (1) shall not appear in a source-expr or mold-expr at
(2)
Index: resolve.c
===================================================================
--- resolve.c (revision 181489)
+++ resolve.c (working copy)
@@ -7173,6 +7173,38 @@ resolve_allocate_deallocate (gfc_code *c
}
}
+ /* If source-expr or mold-expr is a variable, check that it
+ is not an alloc-object. */
+ if (code->expr3 && code->expr3->expr_type == EXPR_VARIABLE)
+ {
+ for (p = code->ext.alloc.list; p; p = p->next)
+ if (p->expr->symtree->n.sym->name == code->expr3->symtree->n.sym->name)
+ {
+ gfc_ref *ref1, *ref2;
+ bool found = true;
+
+ for (ref1 = p->expr->ref, ref2 = code->expr3->ref; ref1 && ref2;
+ ref1 = ref1->next, ref2 = ref2->next)
+ {
+ if (ref1->type != REF_COMPONENT || ref2->type != REF_COMPONENT)
+ continue;
+ if (ref1->u.c.component->name != ref2->u.c.component->name)
+ {
+ found = false;
+ break;
+ }
+ }
+
+ if (found)
+ {
+ gfc_error ("Allocate-object at %L shall not appear in a "
+ "source-expr or mold-expr at %L",
+ &p->expr->where, &code->expr3->where);
+ break;
+ }
+ }
+ }
+
/* Check that an allocate-object appears only once in the statement.
FIXME: Checking derived types is disabled. */
for (p = code->ext.alloc.list; p; p = p->next)
next prev parent reply other threads:[~2011-11-18 18:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-18 10:54 [Bug fortran/51208] New: " burnus at gcc dot gnu.org
2011-11-18 16:10 ` [Bug fortran/51208] " kargl at gcc dot gnu.org
2011-11-18 16:12 ` burnus at gcc dot gnu.org
2011-11-18 19:03 ` sgk at troutmask dot apl.washington.edu [this message]
2011-11-18 19:07 ` burnus at gcc dot gnu.org
2011-11-18 19:55 ` sgk at troutmask dot apl.washington.edu
2013-01-07 23:16 ` dominiq at lps dot ens.fr
2013-01-07 23:37 ` sgk at troutmask dot apl.washington.edu
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=bug-51208-4-lztv6ATEc0@http.gcc.gnu.org/bugzilla/ \
--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).