From patchwork Sun Jan 22 16:15:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 137246 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 2F8FBB6FA8 for ; Mon, 23 Jan 2012 03:15:52 +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=1327853753; 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=mAzPWyB mHitevmn1KS5+U0bBXcI=; b=nTzWRnnZUqIdxFFoPKATnGP569ZqZBnTZqQBvdi yCUeT5wiYUOAJdl+/s0CiFQX/8FXoh68KC6yJlP43OWbvQjwYP0G45JlbEZ5dX87 R6Hx9uDVKieVtxFiWcCEdDPs2+sqmo9dZh3kw9Kn1FBe+CG/LHRhF8s9vnWw1Kn7 2NTY= 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=SO7UT6MjYvCHMvjbSTjbq6AhzX8GTl+5Z5JgVvwSMZv05VCcouuwaQyj4Lqfhz /XhHKrihGuO7Vk/aphPk31358Bg2bVzvIBusrKuaZtYv2kvzA3L1a+IYPUvi5VCV za/lcCUtAH2z94BfrZrtEkijMj0jH1nGx2KZTB5AJskLk=; Received: (qmail 23699 invoked by alias); 22 Jan 2012 16:15:37 -0000 Received: (qmail 23676 invoked by uid 22791); 22 Jan 2012 16:15:35 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 22 Jan 2012 16:15:22 +0000 Received: from [192.168.178.22] (port-92-204-93-204.dynamic.qsc.de [92.204.93.204]) by mx01.qsc.de (Postfix) with ESMTP id 604EF3CAB3; Sun, 22 Jan 2012 17:15:19 +0100 (CET) Message-ID: <4F1C3617.9060902@net-b.de> Date: Sun, 22 Jan 2012 17:15:19 +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] PR41600 - fix ICE with type conversion in default initializer 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 middle end does not like to fold_convert a real number to an integer, but gfortran does not type-convert the expressions of initialization expressions. This patch fixes the issue - and thus part of of the issue of the PR. Build and regtested on x86-64-linux. OK for the trunk? Tobias 2012-01-22 Tobias Burnus PR fortran/41600 * expr.c (gfc_default_initializer): Convert the values if the type does not match. 2012-01-22 Tobias Burnus PR fortran/41600 * gfortran.dg/default_initialization_6.f90: New. diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 7cea780..8565b81 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -3774,7 +3780,13 @@ gfc_default_initializer (gfc_typespec *ts) gfc_constructor *ctor = gfc_constructor_get(); if (comp->initializer) - ctor->expr = gfc_copy_expr (comp->initializer); + { + ctor->expr = gfc_copy_expr (comp->initializer); + if ((comp->ts.type != comp->initializer->ts.type + || comp->ts.kind != comp->initializer->ts.kind) + && !comp->attr.pointer && !comp->attr.proc_pointer) + gfc_convert_type_warn (ctor->expr, &comp->ts, 2, false); + } if (comp->attr.allocatable || (comp->ts.type == BT_CLASS && CLASS_DATA (comp)->attr.allocatable)) --- /dev/null 2012-01-22 08:37:16.127677872 +0100 +++ gcc/gcc/testsuite/gfortran.dg/default_initialization_6.f90 2012-01-22 15:46:16.000000000 +0100 @@ -0,0 +1,11 @@ +! { dg-do compile } +! +! PR fortran/41600 +! + implicit none + type t + integer :: X = -999.0 + end type t + class(t), allocatable :: y(:) + allocate (t :: y(1)) +end