From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6565 invoked by alias); 12 May 2012 12:11:09 -0000 Received: (qmail 6550 invoked by uid 22791); 12 May 2012 12:11:05 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED 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; Sat, 12 May 2012 12:10:53 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/50221] Allocatable string length fails with array assignment Date: Sat, 12 May 2012 12:31: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: X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org 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: 2012-05/txt/msg01305.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50221 --- Comment #2 from Tobias Burnus 2012-05-12 12:10:33 UTC --- The following program illustrates some of the problems: a) If the comment lines are removed (i.e. a module is used), there is no valgrind failure and the result is correct. (Note: It requires the patch from PR 53329 with "ns" replaced by "sym->ns".) b) The program (as is) shows no valgrind failure, but the assignment is wrong: "c3", "c3", "c3" instead of "a1", "b2", "c3". c) If one removes the "save,", the result is as with (b) but valgrind shows many errors of the form: Conditional jump or move depends on uninitialised value(s) at 0x4C2C3A9: memcpy@@GLIBC_2.14 (The same failures one gets for the original program of comment 0.) Looking at the dump for (b) - also in comparison with (a) -, I fail to see why one get's ["c1","c1","c1"] - the code looks correct ("S.0" goes from 1 to 3): __builtin_memcpy ((void *) &(*D.1881)[(S.0 + D.1885) + D.1882], (void *) &const[S.0 + -1], (unsigned long) D.1887); In principle, accessing the second argument wrongly should cause that problem. But that one looks okay. I wonder more about the left as (*D.1881)[...] assumes that the compiler knows the size of one element - I am not sure that that works as ".str" is not yet the right value before the line: character(kind=1)[0:][1:.str] * restrict D.1881; !module m character(len=:), save, allocatable :: str(:) character(len=2), parameter :: const(3) = ["a1", "b2", "c3"] !end !use m call test() if(allocated(str)) deallocate(str) contains subroutine test() call doit() print *, 'strlen=',len(str),' / array size =',size(str) print '(3a)', '>',str(1),'<' print '(3a)', '>',str(2),'<' print '(3a)', '>',str(3),'<' end subroutine test subroutine doit() str = const end subroutine doit end