* trans-types.c (gfc_type_for_size): Return wider type
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 27 Sep 2011 19:17:31 +0000 (19:17 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 27 Sep 2011 19:17:31 +0000 (19:17 +0000)
if no suitable narrower type has been found.
(gfc_type_for_mode): Return NULL_TREE if gfc_type_for_size
returned type doesn't have expected TYPE_MODE.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@179290 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fortran/ChangeLog
gcc/fortran/trans-types.c

index 5900b63..99d2d3c 100644 (file)
@@ -1,3 +1,10 @@
+2011-09-27  Jakub Jelinek  <jakub@redhat.com>
+
+       * trans-types.c (gfc_type_for_size): Return wider type
+       if no suitable narrower type has been found.
+       (gfc_type_for_mode): Return NULL_TREE if gfc_type_for_size
+       returned type doesn't have expected TYPE_MODE.
+
 2011-09-26  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/50515
index 43f1a19..aa8e43b 100644 (file)
@@ -2791,18 +2791,29 @@ gfc_type_for_size (unsigned bits, int unsignedp)
       if (bits == TYPE_PRECISION (intTI_type_node))
        return intTI_type_node;
 #endif
+
+      if (bits <= TYPE_PRECISION (intQI_type_node))
+       return intQI_type_node;
+      if (bits <= TYPE_PRECISION (intHI_type_node))
+       return intHI_type_node;
+      if (bits <= TYPE_PRECISION (intSI_type_node))
+       return intSI_type_node;
+      if (bits <= TYPE_PRECISION (intDI_type_node))
+       return intDI_type_node;
+      if (bits <= TYPE_PRECISION (intTI_type_node))
+       return intTI_type_node;
     }
   else
     {
-      if (bits == TYPE_PRECISION (unsigned_intQI_type_node))
+      if (bits <= TYPE_PRECISION (unsigned_intQI_type_node))
         return unsigned_intQI_type_node;
-      if (bits == TYPE_PRECISION (unsigned_intHI_type_node))
+      if (bits <= TYPE_PRECISION (unsigned_intHI_type_node))
        return unsigned_intHI_type_node;
-      if (bits == TYPE_PRECISION (unsigned_intSI_type_node))
+      if (bits <= TYPE_PRECISION (unsigned_intSI_type_node))
        return unsigned_intSI_type_node;
-      if (bits == TYPE_PRECISION (unsigned_intDI_type_node))
+      if (bits <= TYPE_PRECISION (unsigned_intDI_type_node))
        return unsigned_intDI_type_node;
-      if (bits == TYPE_PRECISION (unsigned_intTI_type_node))
+      if (bits <= TYPE_PRECISION (unsigned_intTI_type_node))
        return unsigned_intTI_type_node;
     }
 
@@ -2823,7 +2834,10 @@ gfc_type_for_mode (enum machine_mode mode, int unsignedp)
   else if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
     base = gfc_complex_types;
   else if (SCALAR_INT_MODE_P (mode))
-    return gfc_type_for_size (GET_MODE_PRECISION (mode), unsignedp);
+    {
+      tree type = gfc_type_for_size (GET_MODE_PRECISION (mode), unsignedp);
+      return type != NULL_TREE && mode == TYPE_MODE (type) ? type : NULL_TREE;
+    }
   else if (VECTOR_MODE_P (mode))
     {
       enum machine_mode inner_mode = GET_MODE_INNER (mode);