This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix wrong assumption in SRA


Hi,

The sra_type_can_be_decomposed_p predicate contains these lines:

	for (t = TYPE_FIELDS (type); t ; t = TREE_CHAIN (t))
	  if (TREE_CODE (t) == FIELD_DECL)
	    {
	      /* Reject incorrectly represented bit fields.  */
	      if (DECL_BIT_FIELD (t)
		  && (tree_low_cst (DECL_SIZE (t), 1)
		      != TYPE_PRECISION (TREE_TYPE (t))))
		goto fail;


This implicitly assumes that TYPE_PRECISION matters for DECL_BIT_FIELD, i.e. 
that bit-fields always have integral type, but that's not true in Ada where 
representation clauses or packing on records can generate DECL_BIT_FIELD with 
aggregate types.

Tested on i586-suse-linux, OK for mainline?


2008-05-27  Eric Botcazou  <ebotcazou@adacore.com>

	* tree-sra.c (sra_type_can_be_decomposed_p) <RECORD_TYPE>: Make sure
	that the bitfield is of integral type before testing its precision.


2008-05-27  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/pack9.ad[sb]: New test.


-- 
Eric Botcazou
Index: tree-sra.c
===================================================================
--- tree-sra.c	(revision 135911)
+++ tree-sra.c	(working copy)
@@ -268,6 +268,7 @@ sra_type_can_be_decomposed_p (tree type)
 	    {
 	      /* Reject incorrectly represented bit fields.  */
 	      if (DECL_BIT_FIELD (t)
+		  && INTEGRAL_TYPE_P (TREE_TYPE (t))
 		  && (tree_low_cst (DECL_SIZE (t), 1)
 		      != TYPE_PRECISION (TREE_TYPE (t))))
 		goto fail;
package Pack9 is

  type R1 is record
    I : Integer;
    C : Character;
  end record;

  type R2 is record
    I1, I2 : Integer;
    A : R1;
  end record;
  pragma Pack(R2);

  type R2_Ptr is access all R2;

  procedure Copy (X, Y : R2_Ptr);

end Pack9;
-- { dg-do compile }
-- { dg-options "-O2 -gnatp -cargs --param sra-max-structure-size=24 --param sra-max-structure-count=6 -fdump-tree-final_cleanup" }

package body Pack9 is

  procedure Copy (X, Y : R2_Ptr) is
    T : R2 := Y.all;
  begin
    if T.I2 /= Y.I2 then
      raise Program_Error;
    end if;
    X.all := T;
  end;

end Pack9;

-- { dg-final { scan-tree-dump-not "__gnat_rcheck" "final_cleanup" } }
-- { dg-final { cleanup-tree-dump "final_cleanup" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]