system.h (CONST_CAST): New.

* system.h (CONST_CAST): New.
	* c-decl.c (c_make_fname_decl): Use it.
	* c-lex.c (cb_ident, lex_string): Likewise.
	* c-typeck.c (free_all_tagged_tu_seen_up_to): Likewise.
	* 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.
	* passes.c (execute_one_pass): Likewise.
	* prefix.c (update_path): Likewise.
	* pretty-print.c (pp_base_destroy_prefix): Likewise.
	* tree.c (build_string): Likewise.

cp:
	* call.c (name_as_c_string): Use CONST_CAST.
	* decl.c (build_decl): Likewise.
	* parser.c (cp_parser_string_literal): Likewise.

fortran:
	* gfortranspec.c (lang_specific_driver): Use CONST_CAST.
	* options.c (gfc_post_options): Likewise.
	* parse.c (parse_omp_structured_block): Likewise.
	* st.c (gfc_free_statement): Likewise.

java:
	* jcf-parse.c (read_class, java_parse_file): Use CONST_CAST.
	* jcf.h (JCF_FINISH): Likewise.

From-SVN: r127344
This commit is contained in:
Kaveh R. Ghazi 2007-08-10 17:53:58 +00:00 committed by Kaveh Ghazi
parent df54b9ab94
commit 68a57691dc
23 changed files with 89 additions and 43 deletions

View File

@ -1,3 +1,17 @@
2007-08-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* system.h (CONST_CAST): New.
* c-decl.c (c_make_fname_decl): Use it.
* c-lex.c (cb_ident, lex_string): Likewise.
* c-typeck.c (free_all_tagged_tu_seen_up_to): Likewise.
* 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.
* passes.c (execute_one_pass): Likewise.
* prefix.c (update_path): Likewise.
* pretty-print.c (pp_base_destroy_prefix): Likewise.
* tree.c (build_string): Likewise.
2007-08-10 Aldy Hernandez <aldyh@redhat.com> 2007-08-10 Aldy Hernandez <aldyh@redhat.com>
* tree-flow-inline.h (is_exec_stmt): Remove. * tree-flow-inline.h (is_exec_stmt): Remove.

View File

@ -2811,7 +2811,7 @@ c_make_fname_decl (tree id, int type_dep)
DECL_ARTIFICIAL (decl) = 1; DECL_ARTIFICIAL (decl) = 1;
init = build_string (length + 1, name); init = build_string (length + 1, name);
free ((char *) name); free (CONST_CAST (name));
TREE_TYPE (init) = type; TREE_TYPE (init) = type;
DECL_INITIAL (decl) = init; DECL_INITIAL (decl) = init;

View File

@ -186,7 +186,7 @@ cb_ident (cpp_reader * ARG_UNUSED (pfile),
if (cpp_interpret_string (pfile, str, 1, &cstr, false)) if (cpp_interpret_string (pfile, str, 1, &cstr, false))
{ {
ASM_OUTPUT_IDENT (asm_out_file, (const char *) cstr.text); ASM_OUTPUT_IDENT (asm_out_file, (const char *) cstr.text);
free ((void *) cstr.text); free (CONST_CAST (cstr.text));
} }
} }
#endif #endif
@ -811,7 +811,7 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string)
(parse_in, strs, concats + 1, &istr, wide)) (parse_in, strs, concats + 1, &istr, wide))
{ {
value = build_string (istr.len, (const char *) istr.text); value = build_string (istr.len, (const char *) istr.text);
free ((void *) istr.text); free (CONST_CAST (istr.text));
if (c_lex_string_translate == -1) if (c_lex_string_translate == -1)
{ {
@ -832,7 +832,7 @@ lex_string (const cpp_token *tok, tree *valp, bool objc_string)
*valp = build_string (istr.len, (const char *) istr.text); *valp = build_string (istr.len, (const char *) istr.text);
valp = &TREE_CHAIN (*valp); valp = &TREE_CHAIN (*valp);
} }
free ((void *) istr.text); free (CONST_CAST (istr.text));
} }
} }
else else

View File

@ -1026,7 +1026,7 @@ free_all_tagged_tu_seen_up_to (const struct tagged_tu_seen_cache *tu_til)
const struct tagged_tu_seen_cache *const tu1 const struct tagged_tu_seen_cache *const tu1
= (const struct tagged_tu_seen_cache *) tu; = (const struct tagged_tu_seen_cache *) tu;
tu = tu1->next; tu = tu1->next;
free ((void *)tu1); free (CONST_CAST (tu1));
} }
tagged_tu_seen_base = tu_til; tagged_tu_seen_base = tu_til;
} }

View File

@ -1,3 +1,9 @@
2007-08-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* call.c (name_as_c_string): Use CONST_CAST.
* decl.c (build_decl): Likewise.
* parser.c (cp_parser_string_literal): Likewise.
2007-08-10 Paolo Carlini <pcarlini@suse.de> 2007-08-10 Paolo Carlini <pcarlini@suse.de>
PR c++/17763 PR c++/17763

View File

@ -5388,7 +5388,7 @@ name_as_c_string (tree name, tree type, bool *free_p)
if (IDENTIFIER_CTOR_OR_DTOR_P (name)) if (IDENTIFIER_CTOR_OR_DTOR_P (name))
{ {
pretty_name pretty_name
= (char *) IDENTIFIER_POINTER (constructor_name (type)); = (char *) CONST_CAST (IDENTIFIER_POINTER (constructor_name (type)));
/* For a destructor, add the '~'. */ /* For a destructor, add the '~'. */
if (name == complete_dtor_identifier if (name == complete_dtor_identifier
|| name == base_dtor_identifier || name == base_dtor_identifier
@ -5409,7 +5409,7 @@ name_as_c_string (tree name, tree type, bool *free_p)
*free_p = true; *free_p = true;
} }
else else
pretty_name = (char *) IDENTIFIER_POINTER (name); pretty_name = (char *) CONST_CAST (IDENTIFIER_POINTER (name));
return pretty_name; return pretty_name;
} }

View File

@ -3368,7 +3368,7 @@ cp_make_fname_decl (tree id, int type_dep)
tree decl = build_decl (VAR_DECL, id, type); tree decl = build_decl (VAR_DECL, id, type);
if (name) if (name)
free ((char *) name); free (CONST_CAST (name));
/* As we're using pushdecl_with_scope, we must set the context. */ /* As we're using pushdecl_with_scope, we must set the context. */
DECL_CONTEXT (decl) = current_function_decl; DECL_CONTEXT (decl) = current_function_decl;

View File

@ -2922,8 +2922,8 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok)
if ((translate ? cpp_interpret_string : cpp_interpret_string_notranslate) if ((translate ? cpp_interpret_string : cpp_interpret_string_notranslate)
(parse_in, strs, count, &istr, wide)) (parse_in, strs, count, &istr, wide))
{ {
value = build_string (istr.len, (char *)istr.text); value = build_string (istr.len, (const char *)istr.text);
free ((void *)istr.text); free (CONST_CAST (istr.text));
TREE_TYPE (value) = wide ? wchar_array_type_node : char_array_type_node; TREE_TYPE (value) = wide ? wchar_array_type_node : char_array_type_node;
value = fix_string_type (value); value = fix_string_type (value);

View File

@ -1,3 +1,10 @@
2007-08-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* gfortranspec.c (lang_specific_driver): Use CONST_CAST.
* options.c (gfc_post_options): Likewise.
* parse.c (parse_omp_structured_block): Likewise.
* st.c (gfc_free_statement): Likewise.
2007-08-10 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> 2007-08-10 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/32933 PR fortran/32933

View File

@ -302,7 +302,7 @@ lang_specific_driver (int *in_argc, const char *const **in_argv,
g77_xargc = argc; g77_xargc = argc;
g77_xargv = argv; g77_xargv = argv;
g77_newargc = 0; g77_newargc = 0;
g77_newargv = (const char **) argv; g77_newargv = (const char **) CONST_CAST (argv);
/* First pass through arglist. /* First pass through arglist.

View File

@ -239,7 +239,7 @@ gfc_post_options (const char **pfilename)
gfc_add_include_path (".", true); gfc_add_include_path (".", true);
if (canon_source_file != gfc_source_file) if (canon_source_file != gfc_source_file)
gfc_free ((void *) canon_source_file); gfc_free (CONST_CAST (canon_source_file));
/* Decide which form the file will be read in as. */ /* Decide which form the file will be read in as. */

View File

@ -2625,7 +2625,7 @@ parse_omp_structured_block (gfc_statement omp_st, bool workshare_stmts_only)
&& strcmp (cp->ext.omp_name, new_st.ext.omp_name) != 0)) && strcmp (cp->ext.omp_name, new_st.ext.omp_name) != 0))
gfc_error ("Name after !$omp critical and !$omp end critical does " gfc_error ("Name after !$omp critical and !$omp end critical does "
"not match at %C"); "not match at %C");
gfc_free ((char *) new_st.ext.omp_name); gfc_free (CONST_CAST (new_st.ext.omp_name));
break; break;
case EXEC_OMP_END_SINGLE: case EXEC_OMP_END_SINGLE:
cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE] cp->ext.omp_clauses->lists[OMP_LIST_COPYPRIVATE]

View File

@ -173,7 +173,7 @@ gfc_free_statement (gfc_code *p)
break; break;
case EXEC_OMP_CRITICAL: case EXEC_OMP_CRITICAL:
gfc_free ((char *) p->ext.omp_name); gfc_free (CONST_CAST (p->ext.omp_name));
break; break;
case EXEC_OMP_FLUSH: case EXEC_OMP_FLUSH:

View File

@ -1881,7 +1881,7 @@ set_spec (const char *name, const char *spec)
/* Free the old spec. */ /* Free the old spec. */
if (old_spec && sl->alloc_p) if (old_spec && sl->alloc_p)
free ((void *) old_spec); free (CONST_CAST(old_spec));
sl->alloc_p = 1; sl->alloc_p = 1;
} }
@ -2186,7 +2186,7 @@ read_specs (const char *filename, int main_p)
set_spec (p2, *(sl->ptr_spec)); set_spec (p2, *(sl->ptr_spec));
if (sl->alloc_p) if (sl->alloc_p)
free ((void *) *(sl->ptr_spec)); free (CONST_CAST (*(sl->ptr_spec)));
*(sl->ptr_spec) = ""; *(sl->ptr_spec) = "";
sl->alloc_p = 0; sl->alloc_p = 0;
@ -2536,18 +2536,18 @@ for_each_path (const struct path_prefix *paths,
Don't repeat any we have already seen. */ Don't repeat any we have already seen. */
if (multi_dir) if (multi_dir)
{ {
free ((char *) multi_dir); free (CONST_CAST (multi_dir));
multi_dir = NULL; multi_dir = NULL;
free ((char *) multi_suffix); free (CONST_CAST (multi_suffix));
multi_suffix = machine_suffix; multi_suffix = machine_suffix;
free ((char *) just_multi_suffix); free (CONST_CAST (just_multi_suffix));
just_multi_suffix = just_machine_suffix; just_multi_suffix = just_machine_suffix;
} }
else else
skip_multi_dir = true; skip_multi_dir = true;
if (multi_os_dir) if (multi_os_dir)
{ {
free ((char *) multi_os_dir); free (CONST_CAST (multi_os_dir));
multi_os_dir = NULL; multi_os_dir = NULL;
} }
else else
@ -2556,12 +2556,12 @@ for_each_path (const struct path_prefix *paths,
if (multi_dir) if (multi_dir)
{ {
free ((char *) multi_dir); free (CONST_CAST (multi_dir));
free ((char *) multi_suffix); free (CONST_CAST (multi_suffix));
free ((char *) just_multi_suffix); free (CONST_CAST (just_multi_suffix));
} }
if (multi_os_dir) if (multi_os_dir)
free ((char *) multi_os_dir); free (CONST_CAST (multi_os_dir));
if (ret != path) if (ret != path)
free (path); free (path);
return ret; return ret;
@ -2968,7 +2968,7 @@ execute (void)
errmsg = pex_run (pex, errmsg = pex_run (pex,
((i + 1 == n_commands ? PEX_LAST : 0) ((i + 1 == n_commands ? PEX_LAST : 0)
| (string == commands[i].prog ? PEX_SEARCH : 0)), | (string == commands[i].prog ? PEX_SEARCH : 0)),
string, (char * const *) commands[i].argv, string, (char * const *) CONST_CAST (commands[i].argv),
NULL, NULL, &err); NULL, NULL, &err);
if (errmsg != NULL) if (errmsg != NULL)
{ {
@ -2982,7 +2982,7 @@ execute (void)
} }
if (string != commands[i].prog) if (string != commands[i].prog)
free ((void *) string); free (CONST_CAST (string));
} }
execution_count++; execution_count++;
@ -5023,7 +5023,7 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
for (i = 0, j = 0; i < max; i++) for (i = 0, j = 0; i < max; i++)
if (outfiles[i]) if (outfiles[i])
{ {
argv[j] = (char *) outfiles[i]; argv[j] = (char *) CONST_CAST (outfiles[i]);
j++; j++;
} }
argv[j] = NULL; argv[j] = NULL;
@ -5979,13 +5979,13 @@ give_switch (int switchnum, int omit_first_word)
while (length-- && !IS_DIR_SEPARATOR (arg[length])) while (length-- && !IS_DIR_SEPARATOR (arg[length]))
if (arg[length] == '.') if (arg[length] == '.')
{ {
((char *)arg)[length] = 0; ((char *)CONST_CAST(arg))[length] = 0;
dot = 1; dot = 1;
break; break;
} }
do_spec_1 (arg, 1, NULL); do_spec_1 (arg, 1, NULL);
if (dot) if (dot)
((char *)arg)[length] = '.'; ((char *)CONST_CAST(arg))[length] = '.';
do_spec_1 (suffix_subst, 1, NULL); do_spec_1 (suffix_subst, 1, NULL);
} }
else else
@ -7438,7 +7438,7 @@ set_multilib_dir (void)
if (multilib_dir == NULL && multilib_os_dir != NULL if (multilib_dir == NULL && multilib_os_dir != NULL
&& strcmp (multilib_os_dir, ".") == 0) && strcmp (multilib_os_dir, ".") == 0)
{ {
free ((char *) multilib_os_dir); free (CONST_CAST (multilib_os_dir));
multilib_os_dir = NULL; multilib_os_dir = NULL;
} }
else if (multilib_dir != NULL && multilib_os_dir == NULL) else if (multilib_dir != NULL && multilib_os_dir == NULL)

View File

@ -197,9 +197,9 @@ string_seq (void)
l1 = strlen (s1); l1 = strlen (s1);
l2 = strlen (s2); l2 = strlen (s2);
buf = XRESIZEVEC (char, s1, l1 + l2 + 1); buf = XRESIZEVEC (char, CONST_CAST(s1), l1 + l2 + 1);
memcpy (buf + l1, s2, l2 + 1); memcpy (buf + l1, s2, l2 + 1);
XDELETE (s2); XDELETE (CONST_CAST (s2));
s1 = buf; s1 = buf;
} }
return s1; return s1;
@ -221,8 +221,8 @@ typedef_name (void)
c2 = require (ID); c2 = require (ID);
require (')'); require (')');
r = concat ("VEC_", c1, "_", c2, (char *)0); r = concat ("VEC_", c1, "_", c2, (char *)0);
free ((void *)c1); free (CONST_CAST (c1));
free ((void *)c2); free (CONST_CAST (c2));
return r; return r;
} }
else else

View File

@ -1,3 +1,8 @@
2007-08-10 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* jcf-parse.c (read_class, java_parse_file): Use CONST_CAST.
* jcf.h (JCF_FINISH): Likewise.
2007-07-31 Nick Clifton <nickc@redhat.com> 2007-07-31 Nick Clifton <nickc@redhat.com>
* java-gimplify.c: Change copyright header to refer to version 3 * java-gimplify.c: Change copyright header to refer to version 3

View File

@ -1301,7 +1301,7 @@ read_class (tree name)
if (path_name == 0) if (path_name == 0)
return 0; return 0;
else else
free((char *) path_name); free(CONST_CAST (path_name));
} }
current_jcf = jcf; current_jcf = jcf;
@ -1783,7 +1783,7 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
file_list = list; file_list = list;
} }
else else
list = (char *) main_input_filename; list = (char *) CONST_CAST (main_input_filename);
while (list) while (list)
{ {

View File

@ -164,8 +164,8 @@ typedef struct JCF GTY(()) {
#define JCF_FINISH(JCF) { \ #define JCF_FINISH(JCF) { \
CPOOL_FINISH(&(JCF)->cpool); \ CPOOL_FINISH(&(JCF)->cpool); \
if ((JCF)->buffer) free ((JCF)->buffer); \ if ((JCF)->buffer) free ((JCF)->buffer); \
if ((JCF)->filename) free ((char *) (JCF)->filename); \ if ((JCF)->filename) free (CONST_CAST ((JCF)->filename)); \
if ((JCF)->classname) free ((char *) (JCF)->classname); \ if ((JCF)->classname) free (CONST_CAST ((JCF)->classname)); \
(JCF)->finished = 1; } (JCF)->finished = 1; }
#define CPOOL_INIT(CPOOL) \ #define CPOOL_INIT(CPOOL) \

View File

@ -1147,7 +1147,7 @@ execute_one_pass (struct tree_opt_pass *pass)
/* Flush and close dump file. */ /* Flush and close dump file. */
if (dump_file_name) if (dump_file_name)
{ {
free ((char *) dump_file_name); free (CONST_CAST (dump_file_name));
dump_file_name = NULL; dump_file_name = NULL;
} }

View File

@ -266,7 +266,7 @@ update_path (const char *path, const char *key)
result = concat (key, &path[len], NULL); result = concat (key, &path[len], NULL);
if (free_key) if (free_key)
free ((char *) key); free (CONST_CAST (key));
result = translate_name (result); result = translate_name (result);
} }
else else

View File

@ -633,7 +633,7 @@ pp_base_destroy_prefix (pretty_printer *pp)
{ {
if (pp->prefix != NULL) if (pp->prefix != NULL)
{ {
free ((char *) pp->prefix); free (CONST_CAST (pp->prefix));
pp->prefix = NULL; pp->prefix = NULL;
} }
} }

View File

@ -766,4 +766,18 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN;
#endif /* GCC >= 3.0 */ #endif /* GCC >= 3.0 */
/* This macro allows casting away const-ness to pass -Wcast-qual
warnings. DO NOT USE THIS UNLESS YOU REALLY HAVE TO! It should
only be used in certain specific cases. One valid case is where
the C standard definitions or prototypes force you to. E.g. if you
need to free a const object, or if you pass a const string to
execv, et al. Another valid use would be in an allocation function
that creates const objects that need to be initialized. Most other
cases should be viewed with extreme caution. */
#ifdef __GNUC__
#define CONST_CAST(X) ((__extension__(union {__typeof(X)_q; void *_v;})(X))._v)
#else
#define CONST_CAST(X) ((void*)(X))
#endif
#endif /* ! GCC_SYSTEM_H */ #endif /* ! GCC_SYSTEM_H */

View File

@ -1194,8 +1194,8 @@ build_string (int len, const char *str)
TREE_CONSTANT (s) = 1; TREE_CONSTANT (s) = 1;
TREE_INVARIANT (s) = 1; TREE_INVARIANT (s) = 1;
TREE_STRING_LENGTH (s) = len; TREE_STRING_LENGTH (s) = len;
memcpy ((char *) TREE_STRING_POINTER (s), str, len); memcpy (CONST_CAST (TREE_STRING_POINTER (s)), str, len);
((char *) TREE_STRING_POINTER (s))[len] = '\0'; ((char *) CONST_CAST (TREE_STRING_POINTER (s)))[len] = '\0';
return s; return s;
} }