[PATCH]: Change CONST_CAST macro to accept a TYPE argument

Kaveh R. GHAZI ghazi@caip.rutgers.edu
Sun Sep 2 08:07:00 GMT 2007


This patch changes the CONST_CAST macro to accept a TYPE argument to align
it better with C++'s const_cast<> operator as discussed here:
http://gcc.gnu.org/ml/gcc-patches/2007-09/msg00032.html

There are two minor cases that arose needing explanation:

I wrote the general CONST_CAST(TYPE,X) macro to go from "const TYPE" to
plain "TYPE".  This works for most cases.  However it doesn't work for
typedef'ed pointers like tree or rtx.  I.e. "const tree" (with a space) is
not the same as "const_tree", or I wouldn't have needed the new const_tree
typedef in the first place.

So I had to pass in the underlying type "union tree_node *" in order for
prefixing it with "const" would work.  I wrote three helper macros for
tree, rtx and basic_block to make it less ugly.

Second issue, there was another case in gfortranspec.c that went outside
the "const TYPE" to "TYPE" paradigm.  Instead it went from "const TYPE
*const*" to "const TYPE **".  I created a generic macro accepting two type
arguments to use in this case and defined everything in terms of that for
all the other macros.  See the hunk in system.h and it should be clear.

Bootstrapped on sparc-sun-solaris2.10, regtest in progress.

Okay for mainline if it passes?

		Thanks,
		--Kaveh


2007-09-01  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* system.h (CONST_CAST2, CONST_CAST_TREE, CONST_CAST_RTX,
	CONST_CAST_BB): New macros for type-specific casts.
	(CONST_CAST): Add a TYPE parameter and define it in terms of
	CONST_CAST2.

	* c-decl.c (c_make_fname_decl): Supply a TYPE for CONST_CAST.
	* c-lex.c (cb_ident, lex_string): Likewise,
	* c-typeck.c (free_all_tagged_tu_seen_up_to): Likewise,
	* config/i386/i386.c (ix86_function_regparm,
	ix86_function_sseregparm): Use CONST_CAST_TREE.
	* config/mmix/mmix.c (mmix_encode_section_info): Supply a TYPE for
	CONST_CAST.
	* gcc.c (set_spec, read_specs, for_each_path, execute, do_spec_1,
	give_switch, set_multilib_dir): Likewise,
	* gengtype-parse.c (string_seq, typedef_name): Likewise,
	* gimple-low.c (block_may_fallthru): Use CONST_CAST_TREE.
	* jump.c (reversed_comparison_code_parts): Use CONST_CAST_RTX.
	* passes.c (execute_one_pass): Supply a TYPE for CONST_CAST.
	* prefix.c (update_path): Likewise,
	* pretty-print.c (pp_base_destroy_prefix): Likewise,
	* rtlanal.c (keep_with_call_p): Use CONST_CAST_RTX.
	* tree-cfg.c (tree_can_merge_blocks_p,
	tree_block_ends_with_condjump_p): Use CONST_CAST_BB.
	* tree-eh.c (lookup_stmt_eh_region_fn): USe CONST_CAST_TREE.
	* tree.c (build_string): Supply a TYPE for CONST_CAST.
	(attribute_list_contained): Use CONST_CAST_TREE.

cp:
	* call.c (name_as_c_string): Supply a TYPE for CONST_CAST.
	* decl.c (cp_make_fname_decl): Likewise,
	* parser.c (cp_parser_string_literal): Likewise,
	* tree.c (pod_type_p, zero_init_p): Use CONST_CAST_TREE.
	* typeck.c (cp_type_quals, cp_type_readonly, cp_has_mutable_p):
	Likewise,

fortran:
	* gfortranspec.c (lang_specific_driver): Use CONST_CAST2.
	* options.c (gfc_post_options): Supply a TYPE for CONST_CAST.
	* parse.c (parse_omp_structured_block): Likewise,
	* st.c (gfc_free_statement): Likewise,

java:
	* jcf-parse.c (read_class, java_parse_file): Supply a TYPE for
	CONST_CAST.
	* jcf.h (JCF_FINISH): Likewise,

diff -rup orig/egcc-SVN20070901/gcc/system.h egcc-SVN20070901/gcc/system.h
--- orig/egcc-SVN20070901/gcc/system.h	2007-09-01 13:21:08.000000000 -0400
+++ egcc-SVN20070901/gcc/system.h	2007-09-01 19:34:07.453256501 -0400
@@ -784,10 +784,14 @@ extern void fancy_abort (const char *, i

 #if defined(__GNUC__) && GCC_VERSION != 4000
 /* GCC 4.0.x has a bug where it may ICE on this expression.  */
-#define CONST_CAST(X) ((__extension__(union {__typeof(X)_q; void *_v;})(X))._v)
+#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((__extension__(union {FROMTYPE _q; TOTYPE _nq;})(X))._nq)
 #else
-#define CONST_CAST(X) ((void*)(X))
+#define CONST_CAST2(TOTYPE,FROMTYPE,X) ((TOTYPE)(FROMTYPE)(X))
 #endif
+#define CONST_CAST(TYPE,X) CONST_CAST2(TYPE, const TYPE, (X))
+#define CONST_CAST_TREE(X) CONST_CAST(union tree_node *, (X))
+#define CONST_CAST_RTX(X) CONST_CAST(struct rtx_def *, (X))
+#define CONST_CAST_BB(X) CONST_CAST(struct basic_block_def *, (X))

 /* Acivate -Wcast-qual as a warning (not an error/-Werror).  */
 #if GCC_VERSION >= 4003
diff -rup orig/egcc-SVN20070901/gcc/c-decl.c egcc-SVN20070901/gcc/c-decl.c
--- orig/egcc-SVN20070901/gcc/c-decl.c	2007-08-29 23:03:43.000000000 -0400
+++ egcc-SVN20070901/gcc/c-decl.c	2007-09-01 18:25:10.833978253 -0400
@@ -2812,7 +2812,7 @@ c_make_fname_decl (tree id, int type_dep
   DECL_ARTIFICIAL (decl) = 1;

   init = build_string (length + 1, name);
-  free (CONST_CAST (name));
+  free (CONST_CAST (char *, name));
   TREE_TYPE (init) = type;
   DECL_INITIAL (decl) = init;

diff -rup orig/egcc-SVN20070901/gcc/c-lex.c egcc-SVN20070901/gcc/c-lex.c
--- orig/egcc-SVN20070901/gcc/c-lex.c	2007-08-30 23:02:51.000000000 -0400
+++ egcc-SVN20070901/gcc/c-lex.c	2007-09-01 18:29:23.960746501 -0400
@@ -187,7 +187,7 @@ cb_ident (cpp_reader * ARG_UNUSED (pfile
       if (cpp_interpret_string (pfile, str, 1, &cstr, false))
 	{
 	  ASM_OUTPUT_IDENT (asm_out_file, (const char *) cstr.text);
-	  free (CONST_CAST (cstr.text));
+	  free (CONST_CAST (unsigned char *, cstr.text));
 	}
     }
 #endif
@@ -941,7 +941,7 @@ lex_string (const cpp_token *tok, tree *
       (parse_in, strs, concats + 1, &istr, wide))
     {
       value = build_string (istr.len, (const char *) istr.text);
-      free (CONST_CAST (istr.text));
+      free (CONST_CAST (unsigned char *, istr.text));

       if (c_lex_string_translate == -1)
 	{
@@ -962,7 +962,7 @@ lex_string (const cpp_token *tok, tree *
 	      *valp = build_string (istr.len, (const char *) istr.text);
 	      valp = &TREE_CHAIN (*valp);
 	    }
-	  free (CONST_CAST (istr.text));
+	  free (CONST_CAST (unsigned char *, istr.text));
 	}
     }
   else
diff -rup orig/egcc-SVN20070901/gcc/c-typeck.c egcc-SVN20070901/gcc/c-typeck.c
--- orig/egcc-SVN20070901/gcc/c-typeck.c	2007-08-25 11:25:45.000000000 -0400
+++ egcc-SVN20070901/gcc/c-typeck.c	2007-09-01 18:30:12.745854002 -0400
@@ -1113,7 +1113,7 @@ free_all_tagged_tu_seen_up_to (const str
       const struct tagged_tu_seen_cache *const tu1
 	= (const struct tagged_tu_seen_cache *) tu;
       tu = tu1->next;
-      free (CONST_CAST (tu1));
+      free (CONST_CAST (struct tagged_tu_seen_cache *, tu1));
     }
   tagged_tu_seen_base = tu_til;
 }
diff -rup orig/egcc-SVN20070901/gcc/config/i386/i386.c egcc-SVN20070901/gcc/config/i386/i386.c
--- orig/egcc-SVN20070901/gcc/config/i386/i386.c	2007-08-30 23:02:50.000000000 -0400
+++ egcc-SVN20070901/gcc/config/i386/i386.c	2007-09-01 19:38:12.274185371 -0400
@@ -2972,7 +2972,7 @@ ix86_function_regparm (const_tree type,
       && flag_unit_at_a_time && !profile_flag)
     {
       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
-      struct cgraph_local_info *i = cgraph_local_info ((tree)CONST_CAST(decl));
+      struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
       if (i && i->local)
 	{
 	  int local_regparm, globals = 0, regno;
@@ -3054,7 +3054,7 @@ ix86_function_sseregparm (const_tree typ
   if (decl && TARGET_SSE_MATH && flag_unit_at_a_time && !profile_flag)
     {
       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
-      struct cgraph_local_info *i = cgraph_local_info ((tree)CONST_CAST(decl));
+      struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
       if (i && i->local)
 	return TARGET_SSE2 ? 2 : 1;
     }
diff -rup orig/egcc-SVN20070901/gcc/config/mmix/mmix.c egcc-SVN20070901/gcc/config/mmix/mmix.c
--- orig/egcc-SVN20070901/gcc/config/mmix/mmix.c	2007-08-23 12:12:20.000000000 -0400
+++ egcc-SVN20070901/gcc/config/mmix/mmix.c	2007-09-01 18:56:44.911601011 -0400
@@ -1141,7 +1141,7 @@ mmix_encode_section_info (tree decl, rtx
       char *newstr;

       /* Why is the return type of ggc_alloc_string const?  */
-      newstr = (char *) CONST_CAST (ggc_alloc_string ("", len + 1));
+      newstr = CONST_CAST (char *, ggc_alloc_string ("", len + 1));

       strcpy (newstr + 1, str);
       *newstr = '@';
diff -rup orig/egcc-SVN20070901/gcc/cp/call.c egcc-SVN20070901/gcc/cp/call.c
--- orig/egcc-SVN20070901/gcc/cp/call.c	2007-08-25 11:25:06.000000000 -0400
+++ egcc-SVN20070901/gcc/cp/call.c	2007-09-01 18:45:12.862625362 -0400
@@ -5388,7 +5388,7 @@ name_as_c_string (tree name, tree type,
   if (IDENTIFIER_CTOR_OR_DTOR_P (name))
     {
       pretty_name
-	= (char *) CONST_CAST (IDENTIFIER_POINTER (constructor_name (type)));
+	= CONST_CAST (char *, IDENTIFIER_POINTER (constructor_name (type)));
       /* For a destructor, add the '~'.  */
       if (name == complete_dtor_identifier
 	  || name == base_dtor_identifier
@@ -5409,7 +5409,7 @@ name_as_c_string (tree name, tree type,
       *free_p = true;
     }
   else
-    pretty_name = (char *) CONST_CAST (IDENTIFIER_POINTER (name));
+    pretty_name = CONST_CAST (char *, IDENTIFIER_POINTER (name));

   return pretty_name;
 }
diff -rup orig/egcc-SVN20070901/gcc/cp/decl.c egcc-SVN20070901/gcc/cp/decl.c
--- orig/egcc-SVN20070901/gcc/cp/decl.c	2007-08-31 23:02:39.000000000 -0400
+++ egcc-SVN20070901/gcc/cp/decl.c	2007-09-01 18:45:42.518327895 -0400
@@ -3461,7 +3461,7 @@ cp_make_fname_decl (tree id, int type_de
   tree decl = build_decl (VAR_DECL, id, type);

   if (name)
-    free (CONST_CAST (name));
+    free (CONST_CAST (char *, name));

   /* As we're using pushdecl_with_scope, we must set the context.  */
   DECL_CONTEXT (decl) = current_function_decl;
diff -rup orig/egcc-SVN20070901/gcc/cp/parser.c egcc-SVN20070901/gcc/cp/parser.c
--- orig/egcc-SVN20070901/gcc/cp/parser.c	2007-08-31 23:02:40.000000000 -0400
+++ egcc-SVN20070901/gcc/cp/parser.c	2007-09-01 18:46:11.597754411 -0400
@@ -2923,7 +2923,7 @@ cp_parser_string_literal (cp_parser *par
       (parse_in, strs, count, &istr, wide))
     {
       value = build_string (istr.len, (const char *)istr.text);
-      free (CONST_CAST (istr.text));
+      free (CONST_CAST (unsigned char *, istr.text));

       TREE_TYPE (value) = wide ? wchar_array_type_node : char_array_type_node;
       value = fix_string_type (value);
diff -rup orig/egcc-SVN20070901/gcc/cp/tree.c egcc-SVN20070901/gcc/cp/tree.c
--- orig/egcc-SVN20070901/gcc/cp/tree.c	2007-09-01 13:20:58.000000000 -0400
+++ egcc-SVN20070901/gcc/cp/tree.c	2007-09-01 19:20:32.338622664 -0400
@@ -2054,7 +2054,7 @@ pod_type_p (const_tree t)
 {
   /* This CONST_CAST is okay because strip_array_types returns it's
      argument unmodified and we assign it to a const_tree.  */
-  t = strip_array_types ((tree)CONST_CAST(t));
+  t = strip_array_types (CONST_CAST_TREE(t));

   if (t == error_mark_node)
     return 1;
@@ -2093,7 +2093,7 @@ zero_init_p (const_tree t)
 {
   /* This CONST_CAST is okay because strip_array_types returns it's
      argument unmodified and we assign it to a const_tree.  */
-  t = strip_array_types ((tree)CONST_CAST(t));
+  t = strip_array_types (CONST_CAST_TREE(t));

   if (t == error_mark_node)
     return 1;
diff -rup orig/egcc-SVN20070901/gcc/cp/typeck.c egcc-SVN20070901/gcc/cp/typeck.c
--- orig/egcc-SVN20070901/gcc/cp/typeck.c	2007-09-01 13:20:58.000000000 -0400
+++ egcc-SVN20070901/gcc/cp/typeck.c	2007-09-01 19:20:58.686597650 -0400
@@ -6945,7 +6945,7 @@ cp_type_quals (const_tree type)
 {
   /* This CONST_CAST is okay because strip_array_types returns it's
      argument unmodified and we assign it to a const_tree.  */
-  type = strip_array_types ((tree)CONST_CAST(type));
+  type = strip_array_types (CONST_CAST_TREE(type));
   if (type == error_mark_node)
     return TYPE_UNQUALIFIED;
   return TYPE_QUALS (type);
@@ -6959,7 +6959,7 @@ cp_type_readonly (const_tree type)
 {
   /* This CONST_CAST is okay because strip_array_types returns it's
      argument unmodified and we assign it to a const_tree.  */
-  type = strip_array_types ((tree)CONST_CAST(type));
+  type = strip_array_types (CONST_CAST_TREE(type));
   return TYPE_READONLY (type);
 }

@@ -6970,7 +6970,7 @@ cp_has_mutable_p (const_tree type)
 {
   /* This CONST_CAST is okay because strip_array_types returns it's
      argument unmodified and we assign it to a const_tree.  */
-  type = strip_array_types ((tree)CONST_CAST(type));
+  type = strip_array_types (CONST_CAST_TREE(type));

   return CLASS_TYPE_P (type) && CLASSTYPE_HAS_MUTABLE (type);
 }
diff -rup orig/egcc-SVN20070901/gcc/fortran/gfortranspec.c egcc-SVN20070901/gcc/fortran/gfortranspec.c
--- orig/egcc-SVN20070901/gcc/fortran/gfortranspec.c	2007-08-21 20:03:08.000000000 -0400
+++ egcc-SVN20070901/gcc/fortran/gfortranspec.c	2007-09-01 19:29:14.161480616 -0400
@@ -302,7 +302,7 @@ lang_specific_driver (int *in_argc, cons
   g77_xargc = argc;
   g77_xargv = argv;
   g77_newargc = 0;
-  g77_newargv = (const char **) CONST_CAST (argv);
+  g77_newargv = CONST_CAST2 (const char **, const char *const *, argv);

   /* First pass through arglist.

diff -rup orig/egcc-SVN20070901/gcc/fortran/options.c egcc-SVN20070901/gcc/fortran/options.c
--- orig/egcc-SVN20070901/gcc/fortran/options.c	2007-08-26 23:02:44.000000000 -0400
+++ egcc-SVN20070901/gcc/fortran/options.c	2007-09-01 18:52:43.976645873 -0400
@@ -244,7 +244,7 @@ gfc_post_options (const char **pfilename
     gfc_add_include_path (".", true);

   if (canon_source_file != gfc_source_file)
-    gfc_free (CONST_CAST (canon_source_file));
+    gfc_free (CONST_CAST (char *, canon_source_file));

   /* Decide which form the file will be read in as.  */

diff -rup orig/egcc-SVN20070901/gcc/fortran/parse.c egcc-SVN20070901/gcc/fortran/parse.c
--- orig/egcc-SVN20070901/gcc/fortran/parse.c	2007-08-26 23:02:44.000000000 -0400
+++ egcc-SVN20070901/gcc/fortran/parse.c	2007-09-01 18:53:13.554351950 -0400
@@ -2636,7 +2636,7 @@ parse_omp_structured_block (gfc_statemen
 	      && strcmp (cp->ext.omp_name, new_st.ext.omp_name) != 0))
 	gfc_error ("Name after !$omp critical and !$omp end critical does "
 		   "not match at %C");
-      gfc_free (CONST_CAST (new_st.ext.omp_name));
+      gfc_free (CONST_CAST (char *, new_st.ext.omp_name));
       break;
     case EXEC_OMP_END_SINGLE:
       cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE]
diff -rup orig/egcc-SVN20070901/gcc/fortran/st.c egcc-SVN20070901/gcc/fortran/st.c
--- orig/egcc-SVN20070901/gcc/fortran/st.c	2007-08-10 14:11:14.000000000 -0400
+++ egcc-SVN20070901/gcc/fortran/st.c	2007-09-01 18:53:30.201400488 -0400
@@ -173,7 +173,7 @@ gfc_free_statement (gfc_code *p)
       break;

     case EXEC_OMP_CRITICAL:
-      gfc_free (CONST_CAST (p->ext.omp_name));
+      gfc_free (CONST_CAST (char *, p->ext.omp_name));
       break;

     case EXEC_OMP_FLUSH:
diff -rup orig/egcc-SVN20070901/gcc/gcc.c egcc-SVN20070901/gcc/gcc.c
--- orig/egcc-SVN20070901/gcc/gcc.c	2007-08-31 23:03:25.000000000 -0400
+++ egcc-SVN20070901/gcc/gcc.c	2007-09-01 18:35:50.729237503 -0400
@@ -1887,7 +1887,7 @@ set_spec (const char *name, const char *

   /* Free the old spec.  */
   if (old_spec && sl->alloc_p)
-    free (CONST_CAST(old_spec));
+    free (CONST_CAST(char *, old_spec));

   sl->alloc_p = 1;
 }
@@ -2192,7 +2192,7 @@ read_specs (const char *filename, int ma

 	      set_spec (p2, *(sl->ptr_spec));
 	      if (sl->alloc_p)
-		free (CONST_CAST (*(sl->ptr_spec)));
+		free (CONST_CAST (char *, *(sl->ptr_spec)));

 	      *(sl->ptr_spec) = "";
 	      sl->alloc_p = 0;
@@ -2542,18 +2542,18 @@ for_each_path (const struct path_prefix
 	 Don't repeat any we have already seen.  */
       if (multi_dir)
 	{
-	  free (CONST_CAST (multi_dir));
+	  free (CONST_CAST (char *, multi_dir));
 	  multi_dir = NULL;
-	  free (CONST_CAST (multi_suffix));
+	  free (CONST_CAST (char *, multi_suffix));
 	  multi_suffix = machine_suffix;
-	  free (CONST_CAST (just_multi_suffix));
+	  free (CONST_CAST (char *, just_multi_suffix));
 	  just_multi_suffix = just_machine_suffix;
 	}
       else
 	skip_multi_dir = true;
       if (multi_os_dir)
 	{
-	  free (CONST_CAST (multi_os_dir));
+	  free (CONST_CAST (char *, multi_os_dir));
 	  multi_os_dir = NULL;
 	}
       else
@@ -2562,12 +2562,12 @@ for_each_path (const struct path_prefix

   if (multi_dir)
     {
-      free (CONST_CAST (multi_dir));
-      free (CONST_CAST (multi_suffix));
-      free (CONST_CAST (just_multi_suffix));
+      free (CONST_CAST (char *, multi_dir));
+      free (CONST_CAST (char *, multi_suffix));
+      free (CONST_CAST (char *, just_multi_suffix));
     }
   if (multi_os_dir)
-    free (CONST_CAST (multi_os_dir));
+    free (CONST_CAST (char *, multi_os_dir));
   if (ret != path)
     free (path);
   return ret;
@@ -2974,7 +2974,7 @@ execute (void)
       errmsg = pex_run (pex,
 			((i + 1 == n_commands ? PEX_LAST : 0)
 			 | (string == commands[i].prog ? PEX_SEARCH : 0)),
-			string, (char * const *) CONST_CAST (commands[i].argv),
+			string, CONST_CAST (char **, commands[i].argv),
 			NULL, NULL, &err);
       if (errmsg != NULL)
 	{
@@ -2988,7 +2988,7 @@ execute (void)
 	}

       if (string != commands[i].prog)
-	free (CONST_CAST (string));
+	free (CONST_CAST (char *, string));
     }

   execution_count++;
@@ -5030,7 +5030,7 @@ do_spec_1 (const char *spec, int inswitc
                   for (i = 0, j = 0; i < max; i++)
                     if (outfiles[i])
                       {
-                        argv[j] = (char *) CONST_CAST (outfiles[i]);
+                        argv[j] = CONST_CAST (char *, outfiles[i]);
                         j++;
                       }
                   argv[j] = NULL;
@@ -5986,13 +5986,13 @@ give_switch (int switchnum, int omit_fir
 	      while (length-- && !IS_DIR_SEPARATOR (arg[length]))
 		if (arg[length] == '.')
 		  {
-		    ((char *)CONST_CAST(arg))[length] = 0;
+		    (CONST_CAST(char *, arg))[length] = 0;
 		    dot = 1;
 		    break;
 		  }
 	      do_spec_1 (arg, 1, NULL);
 	      if (dot)
-		((char *)CONST_CAST(arg))[length] = '.';
+		(CONST_CAST(char *, arg))[length] = '.';
 	      do_spec_1 (suffix_subst, 1, NULL);
 	    }
 	  else
@@ -7445,7 +7445,7 @@ set_multilib_dir (void)
   if (multilib_dir == NULL && multilib_os_dir != NULL
       && strcmp (multilib_os_dir, ".") == 0)
     {
-      free (CONST_CAST (multilib_os_dir));
+      free (CONST_CAST (char *, multilib_os_dir));
       multilib_os_dir = NULL;
     }
   else if (multilib_dir != NULL && multilib_os_dir == NULL)
diff -rup orig/egcc-SVN20070901/gcc/gengtype-parse.c egcc-SVN20070901/gcc/gengtype-parse.c
--- orig/egcc-SVN20070901/gcc/gengtype-parse.c	2007-08-10 14:11:35.000000000 -0400
+++ egcc-SVN20070901/gcc/gengtype-parse.c	2007-09-01 18:27:16.868739585 -0400
@@ -197,9 +197,9 @@ string_seq (void)

       l1 = strlen (s1);
       l2 = strlen (s2);
-      buf = XRESIZEVEC (char, CONST_CAST(s1), l1 + l2 + 1);
+      buf = XRESIZEVEC (char, CONST_CAST(char *, s1), l1 + l2 + 1);
       memcpy (buf + l1, s2, l2 + 1);
-      XDELETE (CONST_CAST (s2));
+      XDELETE (CONST_CAST (char *, s2));
       s1 = buf;
     }
   return s1;
@@ -221,8 +221,8 @@ typedef_name (void)
       c2 = require (ID);
       require (')');
       r = concat ("VEC_", c1, "_", c2, (char *)0);
-      free (CONST_CAST (c1));
-      free (CONST_CAST (c2));
+      free (CONST_CAST (char *, c1));
+      free (CONST_CAST (char *, c2));
       return r;
     }
   else
diff -rup orig/egcc-SVN20070901/gcc/gimple-low.c egcc-SVN20070901/gcc/gimple-low.c
--- orig/egcc-SVN20070901/gcc/gimple-low.c	2007-09-01 13:21:05.000000000 -0400
+++ egcc-SVN20070901/gcc/gimple-low.c	2007-09-01 19:18:49.839175707 -0400
@@ -398,7 +398,7 @@ block_may_fallthru (const_tree block)
 {
   /* This CONST_CAST is okay because expr_last returns it's argument
      unmodified and we assign it to a const_tree.  */
-  const_tree stmt = expr_last ((tree)CONST_CAST(block));
+  const_tree stmt = expr_last (CONST_CAST_TREE(block));

   switch (stmt ? TREE_CODE (stmt) : ERROR_MARK)
     {
diff -rup orig/egcc-SVN20070901/gcc/java/jcf-parse.c egcc-SVN20070901/gcc/java/jcf-parse.c
--- orig/egcc-SVN20070901/gcc/java/jcf-parse.c	2007-08-17 20:02:00.000000000 -0400
+++ egcc-SVN20070901/gcc/java/jcf-parse.c	2007-09-01 18:54:02.647560054 -0400
@@ -1301,7 +1301,7 @@ read_class (tree name)
       if (path_name == 0)
 	return 0;
       else
-	free(CONST_CAST (path_name));
+	free(CONST_CAST (char *, path_name));
     }

   current_jcf = jcf;
@@ -1778,7 +1778,7 @@ java_parse_file (int set_yydebug ATTRIBU
       file_list = list;
     }
   else
-    list = (char *) CONST_CAST (main_input_filename);
+    list = CONST_CAST (char *, main_input_filename);

   while (list)
     {
diff -rup orig/egcc-SVN20070901/gcc/java/jcf.h egcc-SVN20070901/gcc/java/jcf.h
--- orig/egcc-SVN20070901/gcc/java/jcf.h	2007-08-10 14:11:01.000000000 -0400
+++ egcc-SVN20070901/gcc/java/jcf.h	2007-09-01 18:54:57.592643287 -0400
@@ -164,8 +164,8 @@ typedef struct JCF GTY(()) {
 #define JCF_FINISH(JCF) { \
   CPOOL_FINISH(&(JCF)->cpool); \
   if ((JCF)->buffer) free ((JCF)->buffer); \
-  if ((JCF)->filename) free (CONST_CAST ((JCF)->filename)); \
-  if ((JCF)->classname) free (CONST_CAST ((JCF)->classname)); \
+  if ((JCF)->filename) free (CONST_CAST (char *, (JCF)->filename)); \
+  if ((JCF)->classname) free (CONST_CAST (char *, (JCF)->classname)); \
   (JCF)->finished = 1; }

 #define CPOOL_INIT(CPOOL) \
diff -rup orig/egcc-SVN20070901/gcc/jump.c egcc-SVN20070901/gcc/jump.c
--- orig/egcc-SVN20070901/gcc/jump.c	2007-09-01 13:21:05.000000000 -0400
+++ egcc-SVN20070901/gcc/jump.c	2007-09-01 19:22:00.117885570 -0400
@@ -302,9 +302,9 @@ reversed_comparison_code_parts (enum rtx
       /* These CONST_CAST's are okay because prev_nonnote_insn just
 	 returns it's argument and we assign it to a const_rtx
 	 variable.  */
-      for (prev = prev_nonnote_insn ((rtx)(CONST_CAST(insn)));
+      for (prev = prev_nonnote_insn (CONST_CAST_RTX(insn));
 	   prev != 0 && !LABEL_P (prev);
-	   prev = prev_nonnote_insn ((rtx)(CONST_CAST(prev))))
+	   prev = prev_nonnote_insn (CONST_CAST_RTX(prev)))
 	{
 	  const_rtx set = set_of (arg0, prev);
 	  if (set && GET_CODE (set) == SET
diff -rup orig/egcc-SVN20070901/gcc/passes.c egcc-SVN20070901/gcc/passes.c
--- orig/egcc-SVN20070901/gcc/passes.c	2007-08-29 23:03:45.000000000 -0400
+++ egcc-SVN20070901/gcc/passes.c	2007-09-01 18:39:54.638115925 -0400
@@ -1136,7 +1136,7 @@ execute_one_pass (struct tree_opt_pass *
   /* Flush and close dump file.  */
   if (dump_file_name)
     {
-      free (CONST_CAST (dump_file_name));
+      free (CONST_CAST (char *, dump_file_name));
       dump_file_name = NULL;
     }

diff -rup orig/egcc-SVN20070901/gcc/prefix.c egcc-SVN20070901/gcc/prefix.c
--- orig/egcc-SVN20070901/gcc/prefix.c	2007-08-10 14:11:40.000000000 -0400
+++ egcc-SVN20070901/gcc/prefix.c	2007-09-01 18:40:18.322344486 -0400
@@ -266,7 +266,7 @@ update_path (const char *path, const cha

       result = concat (key, &path[len], NULL);
       if (free_key)
-	free (CONST_CAST (key));
+	free (CONST_CAST (char *, key));
       result = translate_name (result);
     }
   else
diff -rup orig/egcc-SVN20070901/gcc/pretty-print.c egcc-SVN20070901/gcc/pretty-print.c
--- orig/egcc-SVN20070901/gcc/pretty-print.c	2007-08-10 14:11:32.000000000 -0400
+++ egcc-SVN20070901/gcc/pretty-print.c	2007-09-01 18:40:34.992438640 -0400
@@ -633,7 +633,7 @@ pp_base_destroy_prefix (pretty_printer *
 {
   if (pp->prefix != NULL)
     {
-      free (CONST_CAST (pp->prefix));
+      free (CONST_CAST (char *, pp->prefix));
       pp->prefix = NULL;
     }
 }
diff -rup orig/egcc-SVN20070901/gcc/rtlanal.c egcc-SVN20070901/gcc/rtlanal.c
--- orig/egcc-SVN20070901/gcc/rtlanal.c	2007-09-01 13:21:03.000000000 -0400
+++ egcc-SVN20070901/gcc/rtlanal.c	2007-09-01 19:22:18.268979854 -0400
@@ -3395,7 +3395,7 @@ keep_with_call_p (const_rtx insn)
 	  /* This CONST_CAST is okay because next_nonnote_insn just
 	     returns it's argument and we assign it to a const_rtx
 	     variable.  */
-	  const_rtx i2 = next_nonnote_insn ((rtx)CONST_CAST(insn));
+	  const_rtx i2 = next_nonnote_insn (CONST_CAST_RTX(insn));
 	  if (i2 && keep_with_call_p (i2))
 	    return true;
 	}
diff -rup orig/egcc-SVN20070901/gcc/tree-cfg.c egcc-SVN20070901/gcc/tree-cfg.c
--- orig/egcc-SVN20070901/gcc/tree-cfg.c	2007-09-01 13:21:10.000000000 -0400
+++ egcc-SVN20070901/gcc/tree-cfg.c	2007-09-01 19:25:49.316665123 -0400
@@ -1160,7 +1160,7 @@ tree_can_merge_blocks_p (const_basic_blo
      cannot merge the blocks.  */
   /* This CONST_CAST is okay because last_stmt doesn't modify its
      argument and the return value is assign to a const_tree.  */
-  stmt = last_stmt ((basic_block)CONST_CAST(a));
+  stmt = last_stmt (CONST_CAST_BB(a));
   if (stmt && stmt_ends_bb_p (stmt))
     return false;

@@ -5922,7 +5922,7 @@ tree_block_ends_with_condjump_p (const_b
 {
   /* This CONST_CAST is okay because last_stmt doesn't modify its
      argument and the return value is not modified.  */
-  const_tree stmt = last_stmt ((basic_block)CONST_CAST(bb));
+  const_tree stmt = last_stmt (CONST_CAST_BB(bb));
   return (stmt && TREE_CODE (stmt) == COND_EXPR);
 }

diff -rup orig/egcc-SVN20070901/gcc/tree-eh.c egcc-SVN20070901/gcc/tree-eh.c
--- orig/egcc-SVN20070901/gcc/tree-eh.c	2007-08-27 00:10:35.000000000 -0400
+++ egcc-SVN20070901/gcc/tree-eh.c	2007-09-01 19:19:36.971878662 -0400
@@ -157,7 +157,7 @@ lookup_stmt_eh_region_fn (struct functio

   /* The CONST_CAST is okay because we don't modify n.stmt throughout
      its scope, or the scope of p.  */
-  n.stmt = (tree) CONST_CAST (t);
+  n.stmt = CONST_CAST_TREE (t);
   p = (struct throw_stmt_node *) htab_find (get_eh_throw_stmt_table (ifun),
                                             &n);

diff -rup orig/egcc-SVN20070901/gcc/tree.c egcc-SVN20070901/gcc/tree.c
--- orig/egcc-SVN20070901/gcc/tree.c	2007-09-01 13:21:03.000000000 -0400
+++ egcc-SVN20070901/gcc/tree.c	2007-09-01 19:20:12.803446055 -0400
@@ -1194,8 +1194,8 @@ build_string (int len, const char *str)
   TREE_CONSTANT (s) = 1;
   TREE_INVARIANT (s) = 1;
   TREE_STRING_LENGTH (s) = len;
-  memcpy (CONST_CAST (TREE_STRING_POINTER (s)), str, len);
-  ((char *) CONST_CAST (TREE_STRING_POINTER (s)))[len] = '\0';
+  memcpy (CONST_CAST (char *, TREE_STRING_POINTER (s)), str, len);
+  ((char *) CONST_CAST (char *, TREE_STRING_POINTER (s)))[len] = '\0';

   return s;
 }
@@ -4795,7 +4795,7 @@ attribute_list_contained (const_tree l1,
 	 modify its argument and the return value is assigned to a
 	 const_tree.  */
       for (attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
-				    (tree)CONST_CAST(l1));
+				    CONST_CAST_TREE(l1));
 	   attr != NULL_TREE;
 	   attr = lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
 				    TREE_CHAIN (attr)))



More information about the Java-patches mailing list