From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2361 invoked by alias); 22 Sep 2008 13:29:47 -0000 Received: (qmail 1756 invoked by uid 48); 22 Sep 2008 13:28:18 -0000 Date: Mon, 22 Sep 2008 13:29:00 -0000 Subject: [Bug fortran/37614] New: Change position of padding for aligned COMMONs X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "burnus at gcc dot gnu dot org" 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: 2008-09/txt/msg02509.txt.bz2 Follow up to PR 37486. see also http://gcc.gnu.org/ml/fortran/2008-09/msg00366.html The following program should print "5" but it prints "0" with default options in gfortran. The problem is that in the program, the common object is padded as <4bytes padding> + i + r8 and then in the subroutine, only the first 4 bytes are read and assigned to the local variable "i". The program is valid as "Named common blocks of the same name shall be of the same size in all scoping units of a program in which they appear, but blank common blocks may be of different sizes." As tests with NAG f95, Portland pgf95 and Pathscale pathf95 show, these compilers use i + <4bytes padding> + r8 which allows this program to run correctly without sacrificing the alignment. (ifort, sunf95 and g95 - and "gfortran -fno-align-commons" work as no padding is added.) There are still used but not standard conform versions which fail (cf. examples in PR 37486) but for those, gfortran has -fno-align-commons. Test program: ---------------------------------------- subroutine one() integer :: i, j common i print *, i ! shall print "5", in gfortran it is "0" ! ! Testing alternative (invalid standard Fortran): ! common i,j ! print *, i,j end subroutine one program test integer :: i real*8 r8 common i, r8 i = 5 r8 = 123457891234d88 call one() end program test ---------------------------------------- If one enables the "common i, j" and runs the program with several compilers, details about their implementation is revealed: - gfortran and g77 print "0 5" - ifort, sunf95 and g95 print "5 1267487353" (= gfortran -fno-align-commons) - pathscale, pgi, and NAG f95 print "5 0" << expected result when PR is fixed -- Summary: Change position of padding for aligned COMMONs Product: gcc Version: 4.4.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: burnus at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37614