This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFA] Fix bit/byte unit thinko in is_aliasing_offset
- From: Olivier Hainque <hainque at act-europe dot fr>
- To: gcc-patches at gcc dot gnu dot org
- Cc: hainque at act-europe dot fr
- Date: Tue, 7 Oct 2003 10:20:43 +0200
- Subject: [RFA] Fix bit/byte unit thinko in is_aliasing_offset
Hello,
At least for Ada, some special circuitry is available to deal with local or
dynamically allocated objects more-than-maximally aligned, that is, the
alignment of which is requested to be greater than BIGGEST_ALIGNMENT.
A number of issues are making the whole Ada scheme severely broken as of
today, as demonstrated on e.g. x86-linux by the testcase provided below.
The patch included here fixes a simple bit/byte unit thinko in
is_aligning_offset, which is part of what's necessary to fix the general
issue.
It bootstraps and passes regression tests fine on i686-pc-linux-gnu, and has
also been tested with another set of patches on sparc-sun-solaris2.8.
The Ada testcase follows.
Olivier
2003-10-07 Olivier Hainque <hainque@act-europe.fr>
* expr.c (is_aligning_offset): Check if we are aligning the
expressions's address over BIGGEST_ALIGNMENT in bytes, not
in bits.
*** gcc/expr.c.ori Fri Oct 3 18:55:28 2003
--- gcc/expr.c Fri Oct 3 18:32:01 2003
*************** is_aligning_offset (offset, exp)
*** 8986,8996 ****
/* We must now have a BIT_AND_EXPR with a constant that is one less than
power of 2 and which is larger than BIGGEST_ALIGNMENT. */
if (TREE_CODE (offset) != BIT_AND_EXPR
|| !host_integerp (TREE_OPERAND (offset, 1), 1)
! || compare_tree_int (TREE_OPERAND (offset, 1), BIGGEST_ALIGNMENT) <= 0
|| !exact_log2 (tree_low_cst (TREE_OPERAND (offset, 1), 1) + 1) < 0)
return 0;
/* Look at the first operand of BIT_AND_EXPR and strip any conversion.
It must be NEGATE_EXPR. Then strip any more conversions. */
--- 8986,8997 ----
/* We must now have a BIT_AND_EXPR with a constant that is one less than
power of 2 and which is larger than BIGGEST_ALIGNMENT. */
if (TREE_CODE (offset) != BIT_AND_EXPR
|| !host_integerp (TREE_OPERAND (offset, 1), 1)
! || compare_tree_int (TREE_OPERAND (offset, 1),
! BIGGEST_ALIGNMENT / BITS_PER_UNIT) <= 0
|| !exact_log2 (tree_low_cst (TREE_OPERAND (offset, 1), 1) + 1) < 0)
return 0;
/* Look at the first operand of BIT_AND_EXPR and strip any conversion.
It must be NEGATE_EXPR. Then strip any more conversions. */
--
m.adb:
with Ada.Text_IO; use Ada.Text_IO;
procedure M is
N_Tries : constant := 3;
type Aligned_T is new Integer;
for Aligned_T'Alignment use Standard'Maximum_Alignment * 2;
type Aligned_A is access Aligned_T;
procedure Dump (X : Aligned_A) is
begin
if X /= null then
Put_Line (Aligned_T'Image (X.all));
else
Put_Line ("null pointer");
end if;
end;
Pointer_To_New : Aligned_A;
Pointer_To_Previous : Aligned_A;
begin
for I in 1 .. N_Tries loop
Pointer_To_Previous := Pointer_To_New;
Pointer_To_New := new Aligned_T;
Pointer_To_New.all := Aligned_T (I);
Put ("Pre => "); Dump (Pointer_To_Previous);
Put ("New => "); Dump (Pointer_To_New);
Put_Line ("-----");
end loop;
end;
expected output:
Pre => null pointer
New => 1
-----
Pre => 1
New => 2
-----
Pre => 2
New => 3
-----