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 PR40081, wrong gimple from SRA


This fixes wrong gimple from SRA created because SRA possibly uses
volatile qualified scalar types as replacements which is obviously
bogus (and at least a missed optimization, but in this case causing
invalid gimple).  The problem is latent since ever, thus I plan
only to fix the trunk and 4.4.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
Also tested on the 4.4 branch, queued for applying there.

Richard.

2009-05-10  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/40081
	* tree-sra.c (instantiate_element): Instantiate scalar replacements
	using the main variant of the element type.  Do not fiddle with
	TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS.

	* g++.dg/torture/pr40081.C: New testcase.

Index: gcc/testsuite/g++.dg/torture/pr40081.C
===================================================================
*** gcc/testsuite/g++.dg/torture/pr40081.C	(revision 0)
--- gcc/testsuite/g++.dg/torture/pr40081.C	(revision 0)
***************
*** 0 ****
--- 1,16 ----
+ struct Atomic_t {
+     Atomic_t(int i) : val(i) { }
+     volatile int val;
+ };
+ class RefCount {
+ public:
+     RefCount(Atomic_t c) : m_count(c)  { }
+     Atomic_t m_count;
+ };
+ class IntrusiveCountableBase {
+     RefCount m_useCount;
+ protected:
+     IntrusiveCountableBase();
+ };
+ IntrusiveCountableBase::IntrusiveCountableBase() : m_useCount(0)  { }
+ 
Index: gcc/tree-sra.c
===================================================================
*** gcc/tree-sra.c	(revision 147317)
--- gcc/tree-sra.c	(working copy)
*************** instantiate_element (struct sra_elt *elt
*** 1277,1283 ****
        nowarn = TREE_NO_WARNING (base_elt->parent->element);
    base = base_elt->element;
  
!   elt->replacement = var = make_rename_temp (elt->type, "SR");
  
    if (DECL_P (elt->element)
        && !tree_int_cst_equal (DECL_SIZE (var), DECL_SIZE (elt->element)))
--- 1277,1284 ----
        nowarn = TREE_NO_WARNING (base_elt->parent->element);
    base = base_elt->element;
  
!   elt->replacement = var = make_rename_temp (TYPE_MAIN_VARIANT (elt->type),
! 					     "SR");
  
    if (DECL_P (elt->element)
        && !tree_int_cst_equal (DECL_SIZE (var), DECL_SIZE (elt->element)))
*************** instantiate_element (struct sra_elt *elt
*** 1286,1292 ****
        DECL_SIZE_UNIT (var) = DECL_SIZE_UNIT (elt->element);
  
        elt->in_bitfld_block = 1;
!       elt->replacement = fold_build3 (BIT_FIELD_REF, elt->type, var,
  				      DECL_SIZE (var),
  				      BYTES_BIG_ENDIAN
  				      ? size_binop (MINUS_EXPR,
--- 1287,1294 ----
        DECL_SIZE_UNIT (var) = DECL_SIZE_UNIT (elt->element);
  
        elt->in_bitfld_block = 1;
!       elt->replacement = fold_build3 (BIT_FIELD_REF,
! 				      TYPE_MAIN_VARIANT (elt->type), var,
  				      DECL_SIZE (var),
  				      BYTES_BIG_ENDIAN
  				      ? size_binop (MINUS_EXPR,
*************** instantiate_element (struct sra_elt *elt
*** 1303,1314 ****
    DECL_SOURCE_LOCATION (var) = DECL_SOURCE_LOCATION (base);
    DECL_ARTIFICIAL (var) = 1;
  
-   if (TREE_THIS_VOLATILE (elt->type))
-     {
-       TREE_THIS_VOLATILE (var) = 1;
-       TREE_SIDE_EFFECTS (var) = 1;
-     }
- 
    if (DECL_NAME (base) && !DECL_IGNORED_P (base))
      {
        char *pretty_name = build_element_name (elt);
--- 1305,1310 ----


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