This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix type homogeneity bug
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 30 Mar 2008 17:19:23 +0200
- Subject: [PATCH] Fix type homogeneity bug
Hi,
The attached Ada testcase triggers a type checking failure:
p.adb: In function 'P':
p.adb:1: error: type mismatch in binary expression
system__unsigned_types__long_long_unsigned
p__Tb1S___XP1
p__Tb2S___XP1
D.202 = D.200 & D.201
introduced by the constant folder. It is passed:
(gdb) frame 4
#4 0x0890c2f5 in fold_build2_stat (code=BIT_IOR_EXPR, type=0x55704a90,
op0=0x557054a0, op1=0x557054c0)
at /home/eric/gnat/gnat-head/src/gcc/fold-const.c:13370
13370 tem = fold_binary (code, type, op0, op1);
(gdb) p debug_tree(type)
<integer_type 0x55704a90 system__unsigned_types__long_long_unsigned
sizes-gimplified public visited unsigned DI
(gdb) p debug_tree(op0)
<nop_expr 0x557054a0
type <integer_type 0x55704a90 system__unsigned_types__long_long_unsigned
sizes-gimplified public visited unsigned DI
size <integer_cst 0x556dd71c constant invariant visited 64>
unit size <integer_cst 0x556dd738 constant invariant visited 8>
align 64 symtab 0 alias set -1 canonical type 0x55704a90 precision 64
min <integer_cst 0x556ff594 0> max <integer_cst 0x556ff578 -1> RM size
<integer_cst 0x556dd71c 64>>
arg 0 <bit_not_expr 0x55705420
type <integer_type 0x55704a28 p__Tb1S___XP1 type <integer_type
0x55704a90 system__unsigned_types__long_long_unsigned>
(gdb) p debug_tree(op1)
<nop_expr 0x557054c0
type <integer_type 0x55704a90 system__unsigned_types__long_long_unsigned
sizes-gimplified public visited unsigned DI
size <integer_cst 0x556dd71c constant invariant visited 64>
unit size <integer_cst 0x556dd738 constant invariant visited 8>
align 64 symtab 0 alias set -1 canonical type 0x55704a90 precision 64
min <integer_cst 0x556ff594 0> max <integer_cst 0x556ff578 -1> RM size
<integer_cst 0x556dd71c 64>>
arg 0 <bit_not_expr 0x55705480
type <integer_type 0x55704f70 p__Tb2S___XP1 type <integer_type
0x55704a90 system__unsigned_types__long_long_unsigned>
and yields:
<bit_and_expr 0x556e1558
type <integer_type 0x55704a90 system__unsigned_types__long_long_unsigned
sizes-gimplified public visited unsigned DI
size <integer_cst 0x556dd71c constant invariant visited 64>
unit size <integer_cst 0x556dd738 constant invariant visited 8>
align 64 symtab 0 alias set -1 canonical type 0x55704a90 precision 64
min <integer_cst 0x556ff594 0> max <integer_cst 0x556ff578 -1> RM size
<integer_cst 0x556dd71c 64>>
arg 0 <component_ref 0x556e8118
type <integer_type 0x55704a28 p__Tb1S___XP1 type <integer_type
0x55704a90 system__unsigned_types__long_long_unsigned>
arg 1 <component_ref 0x556e8140
type <integer_type 0x55704f70 p__Tb2S___XP1 type <integer_type
0x55704a90 system__unsigned_types__long_long_unsigned>
Tested on x86_64-suse-linux, OK for mainline?
2008-03-30 Eric Botcazou <ebotcazou@adacore.com>
* fold-const.c (fold_binary) <BIT_IOR_EXPR>: Add missing conversions.
2008-03-30 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/bit_packed_array2.adb: New test.
--
Eric Botcazou
Index: fold-const.c
===================================================================
--- fold-const.c (revision 133677)
+++ fold-const.c (working copy)
@@ -10420,8 +10420,10 @@ fold_binary (enum tree_code code, tree t
{
return fold_build1 (BIT_NOT_EXPR, type,
build2 (BIT_AND_EXPR, type,
- TREE_OPERAND (arg0, 0),
- TREE_OPERAND (arg1, 0)));
+ fold_convert (type,
+ TREE_OPERAND (arg0, 0)),
+ fold_convert (type,
+ TREE_OPERAND (arg1, 0))));
}
/* See if this can be simplified into a rotate first. If that
-- { dg-do compile }
-- { dg-options "-gnatws" }
procedure Bit_Packed_Array2 is
type Bit_Array is array (integer range <>) of Boolean;
pragma Pack(Bit_Array);
b1 : Bit_Array(1..64);
b2 : Bit_array(1..64);
res : Bit_array(1..64);
begin
if (not((not b1) or (not b2))) /= res then
null;
end if;
end;