[PATCH] Fix attribute handling

Eric Christopher echristo@redhat.com
Fri Oct 11 15:11:00 GMT 2002


Here we go again :)

2002-10-11  Eric Christopher  <echristo@redhat.com>

	
	* output.h (default_valid_pointer_mode): Declare.
	* varasm.c (default_valid_pointer_mode): Define.
	* target-def.h (TARGET_VALID_POINTER_MODE): Use.
	* target.h: Ditto.
	* tree.c (build_pointer_type_for_mode): New function.
	(build_pointer_type): Use.
	(build_reference_type_for_mode): New function.
	(build_reference_type): Use.
	* tree.h: Declare new functions.
	* c-common.c (handle_mode_attribute): Use new functions, check
	for type.
	* stor-layout.c (layout_type): Depend on machine mode for
	REFERENCE_TYPE and POINTER_TYPE.
	* dwarf2out.c (simple_type_size_in_bits): Move upward in file.
	(modified_type_die): Use instead of PTR_SIZE for POINTER_TYPE
	and REFERENCE_TYPE.
	* config/mips/mips.c (mips_valid_pointer_mode): New function.
	(TARGET_VALID_POINTER_MODE): Use and define.
	* config/mips/mips-protos.h (mips_valid_pointer_mode): Declare.

-eric

-- 
Yeah, I used to play basketball...

Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.387
diff -u -p -w -r1.387 c-common.c
--- c-common.c	9 Oct 2002 00:13:56 -0000	1.387
+++ c-common.c	11 Oct 2002 22:02:41 -0000
@@ -5602,6 +5602,7 @@ handle_mode_attribute (node, name, args,
       int len = strlen (p);
       enum machine_mode mode = VOIDmode;
       tree typefm;
+      tree ptr_type;
 
       if (len > 4 && p[0] == '_' && p[1] == '_'
 	  && p[len - 1] == '_' && p[len - 2] == '_')
@@ -5631,6 +5632,10 @@ handle_mode_attribute (node, name, args,
       else if (0 == (typefm = (*lang_hooks.types.type_for_mode)
 		     (mode, TREE_UNSIGNED (type))))
 	error ("no data type for mode `%s'", p);
+      else if ((TREE_CODE (type) == POINTER_TYPE
+		|| TREE_CODE (type) == REFERENCE_TYPE)
+	       && !(*targetm.valid_pointer_mode) (mode))
+	error ("invalid pointer mode `%s'", p);
       else
 	{
 	  /* If this is a vector, make sure we either have hardware
@@ -5643,6 +5648,19 @@ handle_mode_attribute (node, name, args,
 	      return NULL_TREE;
 	    }
 
+	  if (TREE_CODE (type) == POINTER_TYPE)
+	    {
+	      ptr_type = build_pointer_type_for_mode (TREE_TYPE (type),
+						      mode);
+	      *node = ptr_type;
+	    }
+	  else if (TREE_CODE (type) == REFERENCE_TYPE)
+	    {
+	      ptr_type = build_reference_type_for_mode (TREE_TYPE (type),
+							mode);
+	      *node = ptr_type;
+	    }
+	  else
 	  *node = typefm;
 	  /* No need to layout the type here.  The caller should do this.  */
 	}
Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2out.c,v
retrieving revision 1.388
diff -u -p -w -r1.388 dwarf2out.c
--- dwarf2out.c	1 Oct 2002 20:24:52 -0000	1.388
+++ dwarf2out.c	11 Oct 2002 22:02:42 -0000
@@ -7480,6 +7480,27 @@ is_base_type (type)
   return 0;
 }
 
+/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
+   node, return the size in bits for the type if it is a constant, or else
+   return the alignment for the type if the type's size is not constant, or
+   else return BITS_PER_WORD if the type actually turns out to be an
+   ERROR_MARK node.  */
+
+static inline unsigned HOST_WIDE_INT
+simple_type_size_in_bits (type)
+     tree type;
+{
+
+  if (TREE_CODE (type) == ERROR_MARK)
+    return BITS_PER_WORD;
+  else if (TYPE_SIZE (type) == NULL_TREE)
+    return 0;
+  else if (host_integerp (TYPE_SIZE (type), 1))
+    return tree_low_cst (TYPE_SIZE (type), 1);
+  else
+    return TYPE_ALIGN (type);
+}
+
 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
    entry that chains various modifiers in front of the given type.  */
 
@@ -7557,7 +7578,8 @@ modified_type_die (type, is_const_type, 
       else if (code == POINTER_TYPE)
 	{
 	  mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
-	  add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
+	  add_AT_unsigned (mod_type_die, DW_AT_byte_size,
+			   simple_type_size_in_bits (type) / BITS_PER_UNIT);
 #if 0
 	  add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
 #endif
@@ -7566,7 +7588,8 @@ modified_type_die (type, is_const_type, 
       else if (code == REFERENCE_TYPE)
 	{
 	  mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
-	  add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
+	  add_AT_unsigned (mod_type_die, DW_AT_byte_size,
+			   simple_type_size_in_bits (type) / BITS_PER_UNIT);
 #if 0
 	  add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
 #endif
@@ -8419,27 +8442,6 @@ simple_decl_align_in_bits (decl)
      tree decl;
 {
   return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
-}
-
-/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
-   node, return the size in bits for the type if it is a constant, or else
-   return the alignment for the type if the type's size is not constant, or
-   else return BITS_PER_WORD if the type actually turns out to be an
-   ERROR_MARK node.  */
-
-static inline unsigned HOST_WIDE_INT
-simple_type_size_in_bits (type)
-     tree type;
-{
-
-  if (TREE_CODE (type) == ERROR_MARK)
-    return BITS_PER_WORD;
-  else if (TYPE_SIZE (type) == NULL_TREE)
-    return 0;
-  else if (host_integerp (TYPE_SIZE (type), 1))
-    return tree_low_cst (TYPE_SIZE (type), 1);
-  else
-    return TYPE_ALIGN (type);
 }
 
 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
Index: output.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/output.h,v
retrieving revision 1.113
diff -u -p -w -r1.113 output.h
--- output.h	26 Sep 2002 22:25:12 -0000	1.113
+++ output.h	11 Oct 2002 22:02:42 -0000
@@ -532,6 +532,7 @@ extern const char *default_strip_name_en
 extern bool default_binds_local_p PARAMS ((tree));
 extern bool default_binds_local_p_1 PARAMS ((tree, int));
 extern void default_globalize_label PARAMS ((FILE *, const char *));
+extern bool default_valid_pointer_mode PARAMS ((enum machine_mode));
 
 /* Emit data for vtable gc for GNU binutils.  */
 extern void assemble_vtable_entry PARAMS ((struct rtx_def *, HOST_WIDE_INT));
Index: stor-layout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stor-layout.c,v
retrieving revision 1.133
diff -u -p -w -r1.133 stor-layout.c
--- stor-layout.c	1 Oct 2002 18:44:49 -0000	1.133
+++ stor-layout.c	11 Oct 2002 22:02:42 -0000
@@ -1599,15 +1599,15 @@ layout_type (type)
     case POINTER_TYPE:
     case REFERENCE_TYPE:
       {
-	int nbits = ((TREE_CODE (type) == REFERENCE_TYPE
+
+	enum machine_mode mode = ((TREE_CODE (type) == REFERENCE_TYPE
 		      && reference_types_internal)
-		     ? GET_MODE_BITSIZE (Pmode) : POINTER_SIZE);
+				  ? Pmode : TYPE_MODE (type));
 
-	TYPE_MODE (type) = nbits == POINTER_SIZE ? ptr_mode : Pmode;
-	TYPE_SIZE (type) = bitsize_int (nbits);
-	TYPE_SIZE_UNIT (type) = size_int (nbits / BITS_PER_UNIT);
+	TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (mode));
+	TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (mode));
 	TREE_UNSIGNED (type) = 1;
-	TYPE_PRECISION (type) = nbits;
+	TYPE_PRECISION (type) = GET_MODE_BITSIZE (mode);
       }
       break;
 
Index: target-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target-def.h,v
retrieving revision 1.34
diff -u -p -w -r1.34 target-def.h
--- target-def.h	13 Sep 2002 03:44:53 -0000	1.34
+++ target-def.h	11 Oct 2002 22:02:42 -0000
@@ -239,6 +239,10 @@ Foundation, 59 Temple Place - Suite 330,
 #define TARGET_BINDS_LOCAL_P default_binds_local_p
 #endif
 
+#ifndef TARGET_VALID_POINTER_MODE
+#define TARGET_VALID_POINTER_MODE default_valid_pointer_mode
+#endif
+
 /* In hook.c.  */
 #define TARGET_CANNOT_MODIFY_JUMPS_P hook_void_bool_false
 
@@ -271,6 +275,7 @@ Foundation, 59 Temple Place - Suite 330,
   TARGET_BINDS_LOCAL_P,				\
   TARGET_ENCODE_SECTION_INFO,			\
   TARGET_STRIP_NAME_ENCODING,			\
+  TARGET_VALID_POINTER_MODE,                    \
   TARGET_HAVE_NAMED_SECTIONS,			\
   TARGET_HAVE_CTORS_DTORS,			\
   TARGET_HAVE_TLS,				\
Index: target.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target.h,v
retrieving revision 1.37
diff -u -p -w -r1.37 target.h
--- target.h	27 Sep 2002 12:48:03 -0000	1.37
+++ target.h	11 Oct 2002 22:02:42 -0000
@@ -255,6 +255,7 @@ struct gcc_target
   /* Undo the effects of encode_section_info on the symbol string.  */
   const char * (* strip_name_encoding) PARAMS ((const char *));
 
+  bool (* valid_pointer_mode) PARAMS ((enum machine_mode mode));
   /* Leave the boolean fields at the end.  */
 
   /* True if arbitrary sections are supported.  */
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.276
diff -u -p -w -r1.276 tree.c
--- tree.c	11 Oct 2002 21:10:00 -0000	1.276
+++ tree.c	11 Oct 2002 22:02:42 -0000
@@ -3495,26 +3495,24 @@ compare_tree_int (t, u)
    (RECORD_TYPE, UNION_TYPE and ENUMERAL_TYPE nodes are
    constructed by language-dependent code, not here.)  */
 
-/* Construct, lay out and return the type of pointers to TO_TYPE.
-   If such a type has already been constructed, reuse it.  */
-
 tree
-build_pointer_type (to_type)
+build_pointer_type_for_mode (to_type, mode)
      tree to_type;
+     enum machine_mode mode;
 {
   tree t = TYPE_POINTER_TO (to_type);
 
   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
-
-  if (t != 0)
+  if (t != 0 && mode == ptr_mode)
     return t;
 
-  /* We need a new one.  */
   t = make_node (POINTER_TYPE);
 
   TREE_TYPE (t) = to_type;
+  TYPE_MODE (t) = mode;
 
   /* Record this type as the pointer to TO_TYPE.  */
+  if (mode == ptr_mode)
   TYPE_POINTER_TO (to_type) = t;
 
   /* Lay out the type.  This function has many callers that are concerned
@@ -3525,30 +3523,50 @@ build_pointer_type (to_type)
   return t;
 }
 
-/* Build the node for the type of references-to-TO_TYPE.  */
+/* Construct, lay out and return the type of pointers to TO_TYPE.
+   If such a type has already been constructed, reuse it.  */
 
 tree
-build_reference_type (to_type)
+build_pointer_type (to_type)
+     tree to_type;
+{
+  return build_pointer_type_for_mode (to_type, ptr_mode);
+}
+
+
+tree
+build_reference_type_for_mode (to_type, mode)
      tree to_type;
+     enum machine_mode mode;
 {
   tree t = TYPE_REFERENCE_TO (to_type);
 
   /* First, if we already have a type for pointers to TO_TYPE, use it.  */
-
-  if (t)
+  if (t != 0 && mode == ptr_mode)
     return t;
 
-  /* We need a new one.  */
   t = make_node (REFERENCE_TYPE);
 
   TREE_TYPE (t) = to_type;
+  TYPE_MODE (t) = mode;
 
   /* Record this type as the pointer to TO_TYPE.  */
+  if (mode == ptr_mode)
   TYPE_REFERENCE_TO (to_type) = t;
 
   layout_type (t);
 
   return t;
+}
+
+
+/* Build the node for the type of references-to-TO_TYPE.  */
+
+tree
+build_reference_type (to_type)
+     tree to_type;
+{
+  return build_reference_type_for_mode (to_type, ptr_mode);
 }
 
 /* Build a type that is compatible with t but has no cv quals anywhere
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.358
diff -u -p -w -r1.358 tree.h
--- tree.h	2 Oct 2002 18:46:33 -0000	1.358
+++ tree.h	11 Oct 2002 22:02:43 -0000
@@ -2214,7 +2214,9 @@ extern tree make_unsigned_type		PARAMS (
 extern void initialize_sizetypes	PARAMS ((void));
 extern void set_sizetype		PARAMS ((tree));
 extern void fixup_unsigned_type		PARAMS ((tree));
+extern tree build_pointer_type_for_mode PARAMS ((tree, enum machine_mode));
 extern tree build_pointer_type		PARAMS ((tree));
+extern tree build_reference_type_for_mode PARAMS ((tree, enum machine_mode));
 extern tree build_reference_type 	PARAMS ((tree));
 extern tree build_type_no_quals 	PARAMS ((tree));
 extern tree build_index_type		PARAMS ((tree));
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.315
diff -u -p -w -r1.315 varasm.c
--- varasm.c	11 Oct 2002 01:28:24 -0000	1.315
+++ varasm.c	11 Oct 2002 22:02:43 -0000
@@ -5394,6 +5394,15 @@ default_binds_local_p_1 (exp, shlib)
   return local_p;
 }
 
+/* Determine whether or not a pointer mode is valid. Assume defaults
+   of ptr_mode or Pmode - can be overriden.  */
+bool
+default_valid_pointer_mode (mode)
+     enum machine_mode mode;
+{
+  return (mode == ptr_mode || mode == Pmode);
+}
+
 /* Default function to output code that will globalize a label.  A
    target must define GLOBAL_ASM_OP or provide it's own function to
    globalize a label.  */
Index: config/mips/mips-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mips/mips-protos.h,v
retrieving revision 1.29
diff -u -p -w -r1.29 mips-protos.h
--- config/mips/mips-protos.h	1 Oct 2002 10:14:34 -0000	1.29
+++ config/mips/mips-protos.h	11 Oct 2002 22:02:43 -0000
@@ -138,6 +138,8 @@ extern int              mips_legitimate_
 extern int              mips_reg_mode_ok_for_base_p PARAMS ((rtx,
 							     enum machine_mode,
 							     int));
+extern bool             mips_valid_pointer_mode PARAMS ((enum machine_mode));
+
 extern int		m16_uimm3_b PARAMS ((rtx, enum machine_mode));
 extern int		m16_simm4_1 PARAMS ((rtx, enum machine_mode));
 extern int		m16_nsimm4_1 PARAMS ((rtx, enum machine_mode));
Index: config/mips/mips.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mips/mips.c,v
retrieving revision 1.235
diff -u -p -w -r1.235 mips.c
--- config/mips/mips.c	4 Oct 2002 13:50:40 -0000	1.235
+++ config/mips/mips.c	11 Oct 2002 22:02:43 -0000
@@ -660,6 +660,9 @@ const struct mips_cpu_info mips_cpu_info
 #undef TARGET_ENCODE_SECTION_INFO
 #define TARGET_ENCODE_SECTION_INFO mips_encode_section_info
 
+#undef TARGET_VALID_POINTER_MODE
+#define TARGET_VALID_POINTER_MODE mips_valid_pointer_mode
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 /* Return truth value of whether OP can be used as an operands
@@ -8568,6 +8571,14 @@ mips_class_max_nregs (class, mode)
   else
     return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
 }
+
+bool
+mips_valid_pointer_mode (mode)
+     enum machine_mode mode;
+{
+  return (mode == SImode || (TARGET_64BIT && mode == DImode));
+}
+
 
 /* For each mips16 function which refers to GP relative symbols, we
    use a pseudo register, initialized at the start of the function, to



More information about the Gcc-patches mailing list