This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/34028] New: Type mismatch with optimization of ISHFT


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);


-- 
           Summary: Type mismatch with optimization of ISHFT
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code, patch
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fxcoudert at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34028


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]