From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3019 invoked by alias); 7 Feb 2012 14:37:07 -0000 Received: (qmail 2751 invoked by uid 22791); 7 Feb 2012 14:37:06 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 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; Tue, 07 Feb 2012 14:36:53 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/52117] allocated arrays give incorrect results when used with RESHAPE in gcc v4.6.2 Date: Tue, 07 Feb 2012 14:37: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: critical X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: RESOLVED 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-02/txt/msg00717.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52117 --- Comment #7 from Tobias Burnus 2012-02-07 14:36:48 UTC --- (In reply to comment #6) > It compiles/links with the -std:f95 flag, but gives the same wrong results > [qsh@swim SIESTA]$ gfortran -std=f95 reshape.f90 > reshape.f90:37.11: > PAUSE > 1 > Error: Deleted feature: PAUSE statement at (1) > [qsh@swim SIESTA]$ a.out Well, you do not use -std=f95: As the compilation fails with an "ERROR", thus no new "a.out" file is produced. If you then start "a.out", a previously compiled file is used. > (did not change B to B(:,:,:) since that is not a practical solution for us, > lots of reshapes in our code In Fortran 2003, an allocatable (array) on the LHS is automatically allocated (if unallocated) or reallocated (if the shape does not match). Unfortunately, the implementation had a bug, which could appear if the RHS consisted of only a call to an intrinsic function, located the run-time library (libgfortran). Unless you provide me with a time machine, there are only two choices: Avoiding a gfortran version with that bug by using a newer/older version. Or avoiding the (re)allocation on assignment using either compiler flags or modifying the code. The only solutions, I see, which do not require code changes are: - Use any GCC version before GCC 4.6.0; for instance GCC 4.5.x - Use GCC 4.6 older than 2010-11-28 - Use a GCC (any version) newer than 2012-02-03 - Use -fno-realloc-lhs (caveat: Flag not supported before GCC 4.6) - Use -std=f95 (caveat: Requires that the code compiles without error with -std=f95) I personally would use -fno-realloc-lhs [also due to performance reasons] and/or an compiler version without the bug. For completeness, also the following code changes are possible; except for the first one, they are not recommended: - Use an array spec for allocatable LHS, e.g. "B(:,:,:) = " - Don't use allocatables left of " = RESHAPE" - Make the expression on the RHS more complicated: add "+ 0" or surround with "( )". The first solution ("B(:,:,:) = ") has the advantage that it avoids additional checks whether the LHS is allocated and have the correct shape. With Fortran 2003/2008 compilers, adding it improves the performance minutely - and in hot loops it might even matter. That's the reason that gfortran has -fno-realloc-lhs, but also that other compiles have similar flags such as "-assume norealloc_lhs" or "-e w".