* expr.c (expand_expr_real_1) <VIEW_CONVERT_EXPR>: Only use conversion
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 23 Apr 2010 16:16:50 +0000 (16:16 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 23 Apr 2010 16:16:50 +0000 (16:16 +0000)
between modes if both types are integral.

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

gcc/ChangeLog
gcc/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/unchecked_convert5.adb [new file with mode: 0644]

index c7eecfb..6b5feae 100644 (file)
@@ -1,3 +1,8 @@
+2010-04-23  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * expr.c (expand_expr_real_1) <VIEW_CONVERT_EXPR>: Only use conversion
+       between modes if both types are integral.
+
 2010-04-23  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/43572
index e9e5326..e61ad1e 100644 (file)
@@ -9323,9 +9323,8 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
            op0 = force_reg (GET_MODE (op0), op0);
          op0 = gen_lowpart (mode, op0);
        }
-      /* If both modes are integral, then we can convert from one to the
-        other.  */
-      else if (SCALAR_INT_MODE_P (GET_MODE (op0)) && SCALAR_INT_MODE_P (mode))
+      /* If both types are integral, convert from one mode to the other.  */
+      else if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (treeop0)))
        op0 = convert_modes (mode, GET_MODE (op0), op0,
                             TYPE_UNSIGNED (TREE_TYPE (treeop0)));
       /* As a last resort, spill op0 to memory, and reload it in a
index dacc10e..fc5f35f 100644 (file)
@@ -1,3 +1,7 @@
+2010-04-23  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/unchecked_convert5.adb: New test.
+
 2010-04-23  Richard Guenther  <rguenther@suse.de>
 
        PR lto/41734
diff --git a/gcc/testsuite/gnat.dg/unchecked_convert5.adb b/gcc/testsuite/gnat.dg/unchecked_convert5.adb
new file mode 100644 (file)
index 0000000..e3e4312
--- /dev/null
@@ -0,0 +1,22 @@
+-- { dg-do run { target hppa*-*-* sparc*-*-* powerpc*-*-* } }
+
+with Unchecked_Conversion;
+
+procedure Unchecked_Convert5 is
+
+  subtype c_1 is string(1..1);
+
+  function int2c1 is  -- { dg-warning "different sizes" }
+    new unchecked_conversion (source => integer, target => c_1);
+
+  c1 : c_1;
+
+begin
+
+  c1 := int2c1(16#12#);
+
+  if c1 (1) /= ASCII.Nul then
+    raise Program_Error;
+  end if;
+
+end;