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]

Re: [PATCH] Avoid setting MEM_READONLY_P on decls that are not really read-only (PR regression/19813) (take 2)


On Thu, Feb 17, 2005 at 10:07:15AM -0800, Richard Henderson wrote:
> On Thu, Feb 17, 2005 at 10:49:40AM -0500, Jakub Jelinek wrote:
> > 3) only fail the assertion in set_mem_attributes_minus_bitpos if
> >    the base is not DECL_ARTIFICIAL
> 
> Lets do this one for now.  It seems likely that the assert will
> continue to be effective for a while.

Ok to commit then?
Bootstrapped/regtested on
{i386,x86_64,ia64,ppc,ppc64,s390,s390x}-redhat-linux,
all languages but Ada.

2005-02-18  Jakub Jelinek  <jakub@redhat.com>

	PR c++/19813
	* emit-rtl.c (set_mem_attributes_minus_bitpos): Add assertion
	that ref to be marked MEM_READONLY_P doesn't have base that needs
	constructing.

	* decl.c (start_decl_1): Clear TREE_READONLY flag if
	its type has TYPE_NEEDS_CONSTRUCTING.
	(complete_vars): Likewise.

--- gcc/emit-rtl.c.jj	2005-01-04 15:41:28.000000000 +0100
+++ gcc/emit-rtl.c	2005-02-16 12:44:53.777089745 +0100
@@ -1533,7 +1533,12 @@ set_mem_attributes_minus_bitpos (rtx ref
       if (base && DECL_P (base)
 	  && TREE_READONLY (base)
 	  && (TREE_STATIC (base) || DECL_EXTERNAL (base)))
-	MEM_READONLY_P (ref) = 1;
+	{
+	  tree base_type = TREE_TYPE (base);
+	  gcc_assert (!(base_type && TYPE_NEEDS_CONSTRUCTING (base_type))
+		      || DECL_ARTIFICIAL (base));
+	  MEM_READONLY_P (ref) = 1;
+	}
 
       if (TREE_THIS_VOLATILE (t))
 	MEM_VOLATILE_P (ref) = 1;
--- gcc/cp/decl.c.jj	2005-02-16 09:24:13.000000000 +0100
+++ gcc/cp/decl.c	2005-02-16 12:42:55.666217794 +0100
@@ -3823,6 +3823,14 @@ start_decl_1 (tree decl)
      instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
      will be set correctly.  */
   maybe_push_cleanup_level (type);
+
+  /* An object declared 'const' is only readonly after it is
+     initialized.  We don't have any way of expressing this currently,
+     so we need to be conservative and unset TREE_READONLY for types
+     with constructors.  Otherwise aliasing code will ignore stores in
+     an inline constructor.  */
+   if (TYPE_NEEDS_CONSTRUCTING (type))
+     TREE_READONLY (decl) = 0;
 }
 
 /* Handle initialization of references.  DECL, TYPE, and INIT have the
@@ -10913,6 +10921,13 @@ complete_vars (tree type)
 	  /* Complete the type of the variable.  The VAR_DECL itself
 	     will be laid out in expand_expr.  */
 	  complete_type (TREE_TYPE (var));
+	  /* An object declared 'const' is only readonly after it is
+	     initialized.  We don't have any way of expressing this currently,
+	     so we need to be conservative and unset TREE_READONLY for types
+	     with constructors.  Otherwise aliasing code will ignore stores in
+	     an inline constructor.  */
+	  if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (var)))
+	    TREE_READONLY (var) = 0;
 	  /* Remove this entry from the list.  */
 	  *list = TREE_CHAIN (*list);
 	}


	Jakub


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