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]

TYPE_VOLATILE cleanups


Hi,
I have been looking at how C++ represents qualified member function types. This entailed a cleanup of TYPE_VOLATILE and TREE_THIS_VOLATILE. Although the comments in tree.h specify that the former must be used on types and the latter on non-types, this is not enforced. Infact it is not true in a number of places. This patch fixes things up to enforce the distinction.


The C++ change changes SCOPE_REF to be a general expression node rather than a reference. Although A::B is a reference to something, SCOPE_REF does not know what that object is, and in particular operand[0] is a type and not an object. The middle end expects tcc_reference nodes to have operand0 be an object. (This is the same problem as the one I fixed yesterday in Java. Fortunately in C++ we did not reuse a c-common node.)

booted & tested on i686-pc-linux-gnu, ok?

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2005-08-09  Nathan Sidwell  <nathan@codesourcery.com>

	* tree.h (TREE_THIS_VOLATILE): Only accept non-types.
	(TYPE_RETURNS_STACK_DEPRESSED): Add comment about METHOD_TYPEs.
	* c-common.c (handle_const_attribute): Use TYPE_VOLATILE for type.
	* calls.c (flags_from_decl_or_type): Process types and decls
	separately.  Use TYPE_VOLATILE for type.
	* print-tree.c (print_node): Use TYPE_VOLATILE for type.
	* tree-sra.c (instantiate_element): Likewise.
	* tree-ssa-alias.c (create_name_tags, get_tmt_for): Likewise.
	* tree.c (build2_stat): Only copy TREE_THIS_VOLATILE for reference
	nodes.

	* cp/cp-tree.def (SCOPE_REF): Change to expression class.

Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.648
diff -c -3 -p -r1.648 c-common.c
*** c-common.c	24 Jul 2005 21:37:45 -0000	1.648
--- c-common.c	8 Aug 2005 14:58:04 -0000
*************** handle_const_attribute (tree *node, tree
*** 4291,4297 ****
      TREE_TYPE (*node)
        = build_pointer_type
  	(build_type_variant (TREE_TYPE (type), 1,
! 			     TREE_THIS_VOLATILE (TREE_TYPE (type))));
    else
      {
        warning (OPT_Wattributes, "%qE attribute ignored", name);
--- 4291,4297 ----
      TREE_TYPE (*node)
        = build_pointer_type
  	(build_type_variant (TREE_TYPE (type), 1,
! 			     TYPE_VOLATILE (TREE_TYPE (type))));
    else
      {
        warning (OPT_Wattributes, "%qE attribute ignored", name);
Index: calls.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/calls.c,v
retrieving revision 1.399
diff -c -3 -p -r1.399 calls.c
*** calls.c	4 Aug 2005 03:57:40 -0000	1.399
--- calls.c	8 Aug 2005 14:58:10 -0000
*************** flags_from_decl_or_type (tree exp)
*** 590,612 ****
        if (TREE_NOTHROW (exp))
  	flags |= ECF_NOTHROW;
  
!       if (TREE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
  	flags |= ECF_LIBCALL_BLOCK | ECF_CONST;
  
        flags = special_function_p (exp, flags);
      }
!   else if (TYPE_P (exp) && TYPE_READONLY (exp) && ! TREE_THIS_VOLATILE (exp))
!     flags |= ECF_CONST;
! 
!   if (TREE_THIS_VOLATILE (exp))
!     flags |= ECF_NORETURN;
! 
!   /* Mark if the function returns with the stack pointer depressed.   We
!      cannot consider it pure or constant in that case.  */
!   if (TREE_CODE (type) == FUNCTION_TYPE && TYPE_RETURNS_STACK_DEPRESSED (type))
      {
!       flags |= ECF_SP_DEPRESSED;
!       flags &= ~(ECF_PURE | ECF_CONST | ECF_LIBCALL_BLOCK);
      }
  
    return flags;
--- 590,624 ----
        if (TREE_NOTHROW (exp))
  	flags |= ECF_NOTHROW;
  
!       if (TREE_THIS_VOLATILE (exp))
! 	flags |= ECF_NORETURN;
!       else if (TREE_READONLY (exp))
  	flags |= ECF_LIBCALL_BLOCK | ECF_CONST;
  
        flags = special_function_p (exp, flags);
      }
!   else
      {
!       gcc_assert (TYPE_P (exp));
!       
!       if (TYPE_VOLATILE (exp))
! 	flags |= ECF_NORETURN;
!       else if (TYPE_READONLY (exp))
! 	flags |= ECF_CONST;
! 
!       if (TREE_CODE (exp) == FUNCTION_TYPE)
! 	{
! 	  /* Mark if the function returns with the stack pointer
!      	     depressed.  We cannot consider it pure or constant in
!       	     that case.  */
! 	  if (TYPE_RETURNS_STACK_DEPRESSED (type))
! 	    {
! 	      flags |= ECF_SP_DEPRESSED;
! 	      flags &= ~(ECF_PURE | ECF_CONST | ECF_LIBCALL_BLOCK);
! 	    }
! 	}
!       else
! 	gcc_assert (TREE_CODE (exp) == METHOD_TYPE);
      }
  
    return flags;
Index: print-tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/print-tree.c,v
retrieving revision 1.104
diff -c -3 -p -r1.104 print-tree.c
*** print-tree.c	11 Jul 2005 18:28:33 -0000	1.104
--- print-tree.c	8 Aug 2005 14:58:10 -0000
*************** print_node (FILE *file, const char *pref
*** 274,280 ****
      fputs (" invariant", file);
    if (TREE_ADDRESSABLE (node))
      fputs (" addressable", file);
!   if (TREE_THIS_VOLATILE (node))
      fputs (" volatile", file);
    if (TREE_ASM_WRITTEN (node))
      fputs (" asm_written", file);
--- 274,280 ----
      fputs (" invariant", file);
    if (TREE_ADDRESSABLE (node))
      fputs (" addressable", file);
!   if (TYPE_P (node) ? TYPE_VOLATILE (node) : TREE_THIS_VOLATILE (node))
      fputs (" volatile", file);
    if (TREE_ASM_WRITTEN (node))
      fputs (" asm_written", file);
Index: tree-sra.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-sra.c,v
retrieving revision 2.70
diff -c -3 -p -r2.70 tree-sra.c
*** tree-sra.c	5 Aug 2005 02:42:06 -0000	2.70
--- tree-sra.c	8 Aug 2005 14:58:14 -0000
*************** instantiate_element (struct sra_elt *elt
*** 1113,1119 ****
    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;
--- 1113,1119 ----
    DECL_SOURCE_LOCATION (var) = DECL_SOURCE_LOCATION (base);
    DECL_ARTIFICIAL (var) = 1;
  
!   if (TYPE_VOLATILE (elt->type))
      {
        TREE_THIS_VOLATILE (var) = 1;
        TREE_SIDE_EFFECTS (var) = 1;
Index: tree-ssa-alias.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-alias.c,v
retrieving revision 2.109
diff -c -3 -p -r2.109 tree-ssa-alias.c
*** tree-ssa-alias.c	28 Jul 2005 16:29:53 -0000	2.109
--- tree-ssa-alias.c	8 Aug 2005 14:58:15 -0000
*************** create_name_tags (void)
*** 660,666 ****
  	}
  
        TREE_THIS_VOLATILE (pi->name_mem_tag)
! 	  |= TREE_THIS_VOLATILE (TREE_TYPE (TREE_TYPE (ptr)));
  
        /* Mark the new name tag for renaming.  */
        mark_sym_for_renaming (pi->name_mem_tag);
--- 660,666 ----
  	}
  
        TREE_THIS_VOLATILE (pi->name_mem_tag)
! 	  |= TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (ptr)));
  
        /* Mark the new name tag for renaming.  */
        mark_sym_for_renaming (pi->name_mem_tag);
*************** get_tmt_for (tree ptr, struct alias_info
*** 1850,1856 ****
      }
  
    /* If the pointed-to type is volatile, so is the tag.  */
!   TREE_THIS_VOLATILE (tag) |= TREE_THIS_VOLATILE (tag_type);
  
    /* Make sure that the type tag has the same alias set as the
       pointed-to type.  */
--- 1850,1856 ----
      }
  
    /* If the pointed-to type is volatile, so is the tag.  */
!   TREE_THIS_VOLATILE (tag) |= TYPE_VOLATILE (tag_type);
  
    /* Make sure that the type tag has the same alias set as the
       pointed-to type.  */
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.498
diff -c -3 -p -r1.498 tree.c
*** tree.c	28 Jul 2005 16:30:00 -0000	1.498
--- tree.c	8 Aug 2005 14:58:17 -0000
*************** build2_stat (enum tree_code code, tree t
*** 2818,2826 ****
    TREE_CONSTANT (t) = constant;
    TREE_INVARIANT (t) = invariant;
    TREE_SIDE_EFFECTS (t) = side_effects;
!   TREE_THIS_VOLATILE (t)
!     = (TREE_CODE_CLASS (code) == tcc_reference
!        && arg0 && TREE_THIS_VOLATILE (arg0));
  
    return t;
  }
--- 2818,2825 ----
    TREE_CONSTANT (t) = constant;
    TREE_INVARIANT (t) = invariant;
    TREE_SIDE_EFFECTS (t) = side_effects;
!   if (arg0 && TREE_CODE_CLASS (code) == tcc_reference)
!     TREE_THIS_VOLATILE (t) = TREE_THIS_VOLATILE (arg0);
  
    return t;
  }
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.752
diff -c -3 -p -r1.752 tree.h
*** tree.h	4 Aug 2005 18:55:15 -0000	1.752
--- tree.h	8 Aug 2005 14:58:20 -0000
*************** extern void tree_operand_check_failed (i
*** 949,955 ****
     because eventually we may make that a different bit.
  
     If this bit is set in an expression, so is TREE_SIDE_EFFECTS.  */
! #define TREE_THIS_VOLATILE(NODE) ((NODE)->common.volatile_flag)
  
  /* Nonzero means this node will not trap.  In an INDIRECT_REF, means
     accessing the memory pointed to won't generate a trap.  However,
--- 949,955 ----
     because eventually we may make that a different bit.
  
     If this bit is set in an expression, so is TREE_SIDE_EFFECTS.  */
! #define TREE_THIS_VOLATILE(NODE) (NON_TYPE_CHECK(NODE)->common.volatile_flag)
  
  /* Nonzero means this node will not trap.  In an INDIRECT_REF, means
     accessing the memory pointed to won't generate a trap.  However,
*************** struct tree_block GTY(())
*** 1700,1706 ****
    (INTEGER_TYPE_CHECK (NODE)->type.no_force_blk_flag)
  
  /* In a FUNCTION_TYPE, indicates that the function returns with the stack
!    pointer depressed.  */
  #define TYPE_RETURNS_STACK_DEPRESSED(NODE) \
    (FUNCTION_TYPE_CHECK (NODE)->type.no_force_blk_flag)
  
--- 1700,1707 ----
    (INTEGER_TYPE_CHECK (NODE)->type.no_force_blk_flag)
  
  /* In a FUNCTION_TYPE, indicates that the function returns with the stack
!    pointer depressed.  We have no need to support this on METHOD_TYPE,
!    so we don't.  */
  #define TYPE_RETURNS_STACK_DEPRESSED(NODE) \
    (FUNCTION_TYPE_CHECK (NODE)->type.no_force_blk_flag)
  
Index: cp/cp-tree.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.def,v
retrieving revision 1.108
diff -c -3 -p -r1.108 cp-tree.def
*** cp/cp-tree.def	25 Jun 2005 00:58:10 -0000	1.108
--- cp/cp-tree.def	8 Aug 2005 14:58:25 -0000
*************** DEFTREECODE (VEC_DELETE_EXPR, "vec_dl_ex
*** 63,69 ****
  /* Value is reference to particular overloaded class method.
     Operand 0 is the class, operand 1 is the field
     The COMPLEXITY field holds the class level (usually 0).  */
! DEFTREECODE (SCOPE_REF, "scope_ref", tcc_reference, 2)
  
  /* When composing an object with a member, this is the result.
     Operand 0 is the object.  Operand 1 is the member (usually
--- 63,69 ----
  /* Value is reference to particular overloaded class method.
     Operand 0 is the class, operand 1 is the field
     The COMPLEXITY field holds the class level (usually 0).  */
! DEFTREECODE (SCOPE_REF, "scope_ref", tcc_expression, 2)
  
  /* When composing an object with a member, this is the result.
     Operand 0 is the object.  Operand 1 is the member (usually

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