From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17343 invoked by alias); 21 Jul 2010 10:12:54 -0000 Received: (qmail 17262 invoked by uid 48); 21 Jul 2010 10:12:40 -0000 Date: Wed, 21 Jul 2010 10:12:00 -0000 Subject: [Bug fortran/45016] New: Support pointer assignment with bound-spec; wrong bounds for pointer assignment 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: 2010-07/txt/msg02199.txt.bz2 This PR is about two related topics: a) Wrong code: Fortran 90+: The lower bound shall be the same as the one of the object on the RHS b) F2003+ pointer assignment with bounds-spec Related to PR 29785 (bounds remapping). * * * a) WRONG CODE The test case should print twice a lower bound of 2, but currently it prints "1" for the lower bound of pointer "p": !------------------------------- integer, target :: a(2:5,2:5) integer, pointer :: p(:,:) !p(-1:,-1:) => a p => a print *, 'a: ', lbound(a) print *, 'p: ', lbound(p) end !------------------------------- Fortran 90 has: "R736 pointer-assignment-stmt is pointer-object => target" "If the target is not a pointer, the pointer assignment statement associates the pointer-object with the target. If the target is a pointer that is associated, the pointer-object is associated with the same object as the target." Due to the bounds-spec (cf. below) Fortran 2003 is more explicit: "[...] the extent of a dimension of data-pointer-object is the extent of the corresponding dimension of data-target. [...] the lower bound of each dimension is the result of the intrinsic function LBOUND (13.7.60) applied to the corresponding dimension of data-target. The upper bound of each dimension is one less than the sum of the lower bound and the extent." b) BOUND SPEC (cf. 1.7 in the F2003 intro at ftp://ftp.nag.co.uk/sc22wg5/N1601-N1650/N1648.pdf) The following program should have a lower bound of "-1" for the pointer "p". (Works, e.g., with the Cray compiler.) Older gfortrans, e.g. 4.3, accepted this and set the lower bound to 1. Current gfortran reports: Error: Pointer assignment to non-POINTER at (1) !-------------------------------- integer, target :: a(2:5,2:5) integer, pointer :: p(:,:) p(-1:,-1:) => a print *, 'a: ', lbound(a) ! OK, prints "2 2" print *, 'p: ', lbound(p) ! WRONG: prints "1 1", expected: "-1 -1" end !-------------------------------- While Fortran 95 only has: "R736 pointer-assignment-stmt is pointer-object => target" Fortran 2003 (and F2008 as R733) have: "R735 pointer-assignment-stmt is data-pointer-object [ (bounds-spec-list) ] => data-target or data-pointer-object (bounds-remapping-list ) => data-target or proc-pointer-object => proc-target" Further Fortran 2008 quotes (mostly identical to F2003, cf. also item (a)): C716 (R733) If bounds-spec-list is specified, the number of bounds-specs shall equal the rank of data-pointer-object. C718 (R733) If bounds-remapping-list is not specified, the ranks of data-pointer-object and data-target shall be the same. R735 bounds-spec is lower-bound-expr : [Remark: Note that only a lower bound can be specified; no upper or stride] "If no bounds-remapping-list is specified, the extent of a dimension of the pointer object is the extent of the corresponding dimension of the pointer target. If bounds-spec-list appears, it specifies the lower bounds; otherwise, the lower bound of each dimension is the result of the intrinsic function LBOUND (13.7.90) applied to the corresponding dimension of the pointer target. The upper bound of each dimension is one less than the sum of the lower bound and the extent." Expected: The bounds are correctly set. Additionally, the bounds are rejected with -std=f95, -- Summary: Support pointer assignment with bound-spec; wrong bounds for pointer assignment Product: gcc Version: 4.6.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=45016