Bug 34028 - Type mismatch with optimization of ISHFT
Summary: Type mismatch with optimization of ISHFT
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Francois-Xavier Coudert
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2007-11-08 13:20 UTC by Francois-Xavier Coudert
Modified: 2007-11-08 15:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-11-08 13:20:40


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2007-11-08 13:20:20 UTC
Happens on x86-linux, with both -m32 and -m64. Spotted by running the testsuite with -fdefault-integer-8.

$ cat intrinsic_bitops.f90
   implicit none
   integer(kind=4) :: k, o

   o = 0
   k = 12

   if (ishft (k, o+2_8) .ne. 48_8) call abort
end
$ gfortran -O2 intrinsic_bitops.f90
intrinsic_bitops.f90: In function ‘MAIN__’:
intrinsic_bitops.f90:1: error: type mismatch in comparison expression
logical4

int8

int4

if (D.864 <= 31)
  {
    if (o >= -2)
      {
        D.862 = (int8) o;
        D.863 = D.862 + 2;
        D.864 = ABS_EXPR <D.863>;
        D.866 = k << D.864;
        iftmp.2 = D.866 != 48;
      }
    else
      {
        k.3 = (<unnamed-unsigned:32>) k;
        D.862 = (int8) o;
        D.863 = D.862 + 2;
        D.864 = ABS_EXPR <D.863>;
        D.868 = k.3 >> D.864;
        iftmp.2 = D.868 != 48;
      }
    iftmp.1 = iftmp.2;
  }
else
  {
    iftmp.1 = 1;
  }
intrinsic_bitops.f90:1: internal compiler error: verify_gimple failed


The tree dump is:
ABS_EXPR <(int8) o + 2> <= 31 ? o >= -2 ? k << ABS_EXPR <(int8) o + 2> != 48 : (<unnamed-unsigned:32>) k >> ABS_EXPR <(int8) o + 2> != 48 : 1

The problem arises from the fact that 31 above is int4, while ABS_EXPR <(int8) o + 2> is int8. The following patch fixes it:

Index: trans-intrinsic.c
===================================================================
--- trans-intrinsic.c   (revision 129869)
+++ trans-intrinsic.c   (working copy)
@@ -2533,7 +2533,7 @@ gfc_conv_intrinsic_ishft (gfc_se * se, g
   /* The Fortran standard allows shift widths <= BIT_SIZE(I), whereas
      gcc requires a shift width < BIT_SIZE(I), so we have to catch this
      special case.  */
-  num_bits = build_int_cst (TREE_TYPE (args[0]), TYPE_PRECISION (type));
+  num_bits = build_int_cst (TREE_TYPE (args[1]), TYPE_PRECISION (type));
   cond = fold_build2 (GE_EXPR, boolean_type_node, width, num_bits);
Comment 1 Francois-Xavier Coudert 2007-11-08 15:33:33 UTC
Subject: Bug 34028

Author: fxcoudert
Date: Thu Nov  8 15:33:23 2007
New Revision: 130003

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130003
Log:
	PR fortran/34028
	* trans-intrinsic.c (gfc_conv_intrinsic_ishft): Use correct type.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-intrinsic.c

Comment 2 Francois-Xavier Coudert 2007-11-08 15:35:23 UTC
Fixed.