From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2825 invoked by alias); 9 Dec 2010 15:56:54 -0000 Received: (qmail 2808 invoked by uid 22791); 9 Dec 2010 15:56:52 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from taro.utanet.at (HELO taro.utanet.at) (213.90.36.45) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 09 Dec 2010 15:56:47 +0000 Received: from patricia.xoc.tele2net.at ([213.90.36.9]) by taro.utanet.at with esmtp (Exim 4.71) (envelope-from ) id 1PQirM-00064V-3L; Thu, 09 Dec 2010 16:56:44 +0100 Received: from d91-128-23-96.cust.tele2.at ([91.128.23.96] helo=[192.168.1.18]) by patricia.xoc.tele2net.at with esmtpa (Exim 4.71) (envelope-from ) id 1PQirL-0007CX-TK; Thu, 09 Dec 2010 16:56:44 +0100 Message-ID: <4D00FDE6.1050702@domob.eu> Date: Thu, 09 Dec 2010 16:16:00 -0000 From: Daniel Kraft User-Agent: Thunderbird 2.0.0.0 (X11/20070425) MIME-Version: 1.0 To: Tobias Burnus CC: Fortran List , gcc-patches Subject: Re: [Patch, Fortran] PR fortran/46794: Fix ICE with powers of integers References: <4CF97314.4000206@domob.eu> <4CFA00A1.6020101@net-b.de> In-Reply-To: <4CFA00A1.6020101@net-b.de> Content-Type: multipart/mixed; boundary="------------020409010202060501070808" Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2010-12/txt/msg00774.txt.bz2 This is a multi-part message in MIME format. --------------020409010202060501070808 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1146 Tobias Burnus wrote: > Dear Daniel, > > Daniel Kraft wrote: >> I do not entirely like the way this is done in the patch (with the two >> variables and "special casing"), but don't see a better implementation >> -- what do you think? > > I think it is OK - at least I have trouble finding a better solution. > >> Regression-tested on x86_64-unknown-linux-gnu without failures -- >> though the run somehow looked strange to me (on the compile-farm); >> I'll try again to be sure. Ok for trunk? > > OK for the trunk. Can you check whether one needs to likewise for the > 4.5 and 4.4 branch? (I think one should check on source level - the > verify_tree might not always catch it. For some reasons, it ICEs here > with 4.4 and 4.6 but not with 4.5; however, I think that's rather by > chance and not because of a proper casting.) Committed the attached (patch adapted to 4.4 including fix of test-case) as rev. 167644 to 4.4 branch. When 4.5 is open again, I will fix the test-case there, too, and then close the PR. Yours, Daniel -- http://www.pro-vegan.info/ -- Done: Arc-Bar-Cav-Kni-Ran-Rog-Sam-Tou-Val-Wiz To go: Hea-Mon-Pri --------------020409010202060501070808 Content-Type: text/plain; name="patch.changelog" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch.changelog" Content-length: 271 2010-12-09 Daniel Kraft PR fortran/46794 * trans-expr.c (gfc_conv_power_op): Handle kind of result expression correctly for integer kind 1 and 2 operands. 2010-12-09 Daniel Kraft PR fortran/46794 * gfortran.dg/power2.f90: New test. --------------020409010202060501070808 Content-Type: text/plain; name="patch.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch.diff" Content-length: 2467 Index: gcc/testsuite/gfortran.dg/power2.f90 =================================================================== --- gcc/testsuite/gfortran.dg/power2.f90 (revision 0) +++ gcc/testsuite/gfortran.dg/power2.f90 (revision 0) @@ -0,0 +1,25 @@ +! { dg-do compile } +! PR fortran/46794 + +! Check that results of powers of integers with kinds 1 and 2 are +! correctly converted back; this used to ICE because a conversion +! from kind 4 to the correct one was missing. + +! Contributed by Daniel Kraft, d@domob.eu. + +PROGRAM main + IMPLICIT NONE + + INTEGER(KIND=1) :: k1 + INTEGER(KIND=2) :: k2 + + k1 = 1_1 + k2 = 1_2 + + k1 = 1_1 + 1_1**k1 + k2 = 1_2 + 1_2**k2 + + k2 = 1_1 + 1_1**k2 + k2 = 1_1 + 1_2**k1 + k2 = 1_1 + 1_2**k2 +END PROGRAM main Index: gcc/fortran/trans-expr.c =================================================================== --- gcc/fortran/trans-expr.c (revision 167632) +++ gcc/fortran/trans-expr.c (working copy) @@ -917,6 +917,7 @@ tree gfc_int4_type_node; int kind; int ikind; + int res_ikind_1, res_ikind_2; gfc_se lse; gfc_se rse; tree fndecl; @@ -937,6 +938,13 @@ gfc_int4_type_node = gfc_get_int_type (4); + /* In case of integer operands with kinds 1 or 2, we call the integer kind 4 + library routine. But in the end, we have to convert the result back + if this case applies -- with res_ikind_K, we keep track whether operand K + falls into this case. */ + res_ikind_1 = -1; + res_ikind_2 = -1; + kind = expr->value.op.op1->ts.kind; switch (expr->value.op.op2->ts.type) { @@ -947,6 +955,7 @@ case 1: case 2: rse.expr = convert (gfc_int4_type_node, rse.expr); + res_ikind_2 = ikind; /* Fall through. */ case 4: @@ -969,7 +978,10 @@ case 1: case 2: if (expr->value.op.op1->ts.type == BT_INTEGER) - lse.expr = convert (gfc_int4_type_node, lse.expr); + { + lse.expr = convert (gfc_int4_type_node, lse.expr); + res_ikind_1 = kind; + } else gcc_unreachable (); /* Fall through. */ @@ -1080,6 +1092,15 @@ } se->expr = build_call_expr (fndecl, 2, lse.expr, rse.expr); + + /* Convert the result back if it is of wrong integer kind. */ + if (res_ikind_1 != -1 && res_ikind_2 != -1) + { + /* We want the maximum of both operand kinds as result. */ + if (res_ikind_1 < res_ikind_2) + res_ikind_1 = res_ikind_2; + se->expr = convert (gfc_get_int_type (res_ikind_1), se->expr); + } } --------------020409010202060501070808--