From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6699 invoked by alias); 14 Jan 2011 09:00:35 -0000 Received: (qmail 6689 invoked by uid 22791); 14 Jan 2011 09:00:34 -0000 X-SWARE-Spam-Status: No, hits=-2.8 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; Fri, 14 Jan 2011 09:00:25 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/38536] ICE with C_LOC in resolve.c due to not properly going through expr->ref X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: mikael 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 Date: Fri, 14 Jan 2011 09:59:00 -0000 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-01/txt/msg01322.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38536 --- Comment #19 from Tobias Burnus 2011-01-14 09:00:20 UTC --- (In reply to comment #18) > (I asked on comp.lang.fortran) Cf. http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/4b65b1cd206ce9fe Or from the standard (F2008): "15.2.3.6 C LOC (X)": "Argument. X [...] shall not be a coindexed object. [...] If it is an array, it shall be contiguous and have nonzero size." > We just have to check for array sections along the references, and error > out if there are any. I was about to suggest to use gfc_simply_contiguous() but I then realized that -- for a simply contiguous array "array" -- also the following array section array([1,2,3,4]) is contiguous - even though it is not simply contiguous and in the general case the contiguity is not compile-time checkable. (vector-subscripts are notoriously difficult to check at compile time) Similarly, c_loc(comp(1:2)%elem) is valid as long as "elem" is the only item in the derived type *and* no padding is happening. (As padding often occurs, one could always reject it.) And comp(1:1)%elem is always contiguous - but that's also a strange way of writing it. (Actually, I think that comp(1:1)%elem _is_ simply contiguous - though I am not sure gfc_simply_contiguous does detect this.) Personally, I think one should give some diagnostic as soon as the argument is not simply contiguous -- be it a warning or an error. At least I cannot imagine any sensible program using non-simply contiguous arrays as argument for C_LOC. (The term simply contiguous is defined in section 6.5.4.) * * * When you add another check for C_LOC, can you include one for the following? You just need to add a "gfc_is_coindexed (expr)". use iso_c_binding type t integer :: A end type t type(t), target, allocatable :: x(:)[:] type(c_ptr) :: cptr allocate(x(1)[*]) cptr = c_loc(x(1)%a) ! OK cptr = c_loc(x(1)[1]%a) ! Invalid end