From patchwork Fri Jan 13 14:07:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 135844 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id B8A8AB6F65 for ; Sat, 14 Jan 2012 01:07:58 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1327068480; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=IqwUJB9 kYqxscpzQiIj8Ybc5zeY=; b=UQfBv7PRzwYUJm4iQc5gAqLr1T5T0XWDvwDKWvI U1Mwy8ERY+8KLvG5LjW21ZCPVjdQl06kbfCCspoPt4V3aNV2nFXTwSpfOIQKFAJS WdARyuv46Y5BbQQopcVFQRV1KZiJon6AK8eWpg83FHA0SEi5zf3xUAczSqdk4m22 dOvI= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=h8d/liavL8QNRT5pMc3DzR90X7ZrW0eU6pxbb31KhO8QnKNosXK9oEJ8LFLQtS fppyvQUwKZk+DwmpinhVi7S779rtazYnO1KstWNa6k7GyXWzHh/vhV+OcvYOnpZX JoC6bw/u98O7uKm+1vj44PtK6O9jukK2wfckx3KVjXIf4=; Received: (qmail 12540 invoked by alias); 13 Jan 2012 14:07:47 -0000 Received: (qmail 12522 invoked by uid 22791); 13 Jan 2012 14:07:46 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, TW_BG X-Spam-Check-By: sourceware.org Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 13 Jan 2012 14:07:13 +0000 Received: from [192.168.178.22] (port-92-204-59-150.dynamic.qsc.de [92.204.59.150]) by mx02.qsc.de (Postfix) with ESMTP id 3FCB124CEA; Fri, 13 Jan 2012 15:07:10 +0100 (CET) Message-ID: <4F103A8E.3020702@net-b.de> Date: Fri, 13 Jan 2012 15:07:10 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111220 Thunderbird/9.0 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR 51842 use ptrdiff_t for array indices Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Dear all, the front end uses for array indices (gfc_index_integer_kind / gfc_array_index_type) which is a signed integer of size POINTER_SIZE. The libgfortran library used to use typedef ssize_t index_type; which fails if sizeof(void*) is not sizeof(ssize_t); the latter is the case on LP64 systems (see PR). For 4.7 this was changed (in April 2011) to: typedef ptrdiff_t index_type; which makes more sense - and should be sufficient for LP64 systems. However, mixing an POINTER_SIZE type with ptrdiff_t only works if sizeof(ptrdiff_t) == POINTER_SIZE; in principle, the maximally allowed size of a variable can be smaller (e.g. page size) than the maximally allowed pointer size. (sizeof() returns a result of type size_t). I do not know whether such systems exist in practice and whether such a system is supported by GCC. The attached patch makes let's the FE emit code of the same data type as used in libgfortran - ptrdiff_t for the array indices. Build and regtested on x86-64-linux. OK for the trunk? Tobias 2012-01-13 Tobias Burnus PR fortran/51842 * fortran/trans-types.c (gfc_init_kinds): Use PTRDIFF_TYPE instead of a signed int of size POINTER_SIZE for gfc_index_integer_kind. diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c index d643c2e..f817a12 100644 --- a/gcc/fortran/trans-types.c +++ b/gcc/fortran/trans-types.c @@ -576,8 +576,8 @@ gfc_init_kinds (void) gfc_default_character_kind = gfc_character_kinds[0].kind; gfc_character_storage_size = gfc_default_character_kind * 8; - /* Choose the integer kind the same size as "void*" for our index kind. */ - gfc_index_integer_kind = POINTER_SIZE / 8; + gfc_index_integer_kind = get_int_kind_from_name (PTRDIFF_TYPE); + /* Pick a kind the same size as the C "int" type. */ gfc_c_int_kind = INT_TYPE_SIZE / 8;