From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1878 invoked by alias); 18 Nov 2011 18:41:54 -0000 Received: (qmail 1867 invoked by uid 22791); 18 Nov 2011 18:41:53 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_SG X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 18 Nov 2011 18:41:14 +0000 From: "sgk at troutmask dot apl.washington.edu" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: accepts-invalid, diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: sgk at troutmask dot apl.washington.edu X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-11/txt/msg01916.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51208 --- Comment #3 from Steve Kargl 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)