This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix minor bug in VIEW_CONVERT_EXPR expander
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 23 Apr 2010 18:17:09 +0200
- Subject: Fix minor bug in VIEW_CONVERT_EXPR expander
There is a minor bug in the VIEW_CONVERT_EXPR expander in the 4.x series of
compilers, visible mostly on big-endian platforms:
/* 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))
op0 = convert_modes (mode, GET_MODE (op0), op0,
TYPE_UNSIGNED (TREE_TYPE (treeop0)));
Integral mode doesn't imply integral type, the type can be a small record or
array, in which case the TYPE_UNSIGNED test doesn't make sense and the result
is wrong on big-endian platforms.
Fixed thusly, tested on x86_64-suse-linux and SPARC/Solaris, applied on the
mainline as obvious.
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 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/unchecked_convert5.adb: New test.
--
Eric Botcazou
Index: expr.c
===================================================================
--- expr.c (revision 158539)
+++ expr.c (working copy)
@@ -9353,9 +9353,8 @@ expand_expr_real_1 (tree exp, rtx target
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
-- { 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;