From 3521b33c2fcc3f132e9b643042dad7caa5e46b15 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Mon, 23 Feb 2004 21:43:18 +0000 Subject: [PATCH] Remove -fwritable-strings. gcc/ Remove -fwritable-strings. * c-common.c (fix_string_type): Don't check flag_writable_strings. (fix_string_type): Likewise. * c-opts.c (set_std_c89): Don't initialize flag_writable_strings. (set_std_c99): Likewise. * common.opt (fwritable-strings): Remove. * flags.h: Remove the external declaration of flag_writable_strings. * opts.c (common_handle_option) : Remove. * toplev.c (flag_writable_strings): Remove. (f_options): Remove an entry for writable-strings. * varasm.c (const_hash_1) : Don't check flag_writable_strings. (compare_constant) : Likewise. (build_constant_desc): Likewise. * config/darwin.c (machopic_select_section): Likewise. * config/arm/arm.c (AOF_ASSEMBLER): Likewise. * config/arm/pe.c (arm_pe_encode_section_info): Likewise. * config/iq2000/iq2000.c (iq2000_select_section): Likewise. * config/mips/mips.c (mips_select_section): Likewise. (mips_encode_section_info): Likewise. * config/pa/pa.c (pa_select_section): Likewise. * config/pa/pa.h (TEXT_SPACE_P): Likewise. * config/v850/v850.c (v850_select_section): Likewise. * doc/invoke.texi (-fwritable-strings): Remove. (-fno-const-strings): Don't mention -fwritable-strings. * doc/trouble.texi: Don't mention -fwritable-strings. gcc/cp/ * decl.c (cxx_init_decl_processing): Don't check flag_writable_strings. gcc/testsuite/ * gcc.dg/fwritable-strings-1.c: Remove. Co-Authored-By: Kazu Hirata From-SVN: r78333 --- gcc/ChangeLog | 34 +++++++++++++++++++++++++++++ gcc/c-common.c | 4 ++-- gcc/c-opts.c | 2 -- gcc/common.opt | 4 ---- gcc/config/arm/arm.c | 3 +-- gcc/config/arm/pe.c | 3 +-- gcc/config/darwin.c | 3 +-- gcc/config/iq2000/iq2000.c | 32 ++++++++++++--------------- gcc/config/mips/mips.c | 7 ++---- gcc/config/pa/pa.c | 1 - gcc/config/pa/pa.h | 3 +-- gcc/config/v850/v850.c | 7 ------ gcc/cp/ChangeLog | 6 +++++ gcc/cp/decl.c | 5 ----- gcc/doc/invoke.texi | 17 ++------------- gcc/doc/trouble.texi | 15 +++++-------- gcc/flags.h | 5 ----- gcc/opts.c | 4 ---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/fwritable-strings-1.c | 18 --------------- gcc/toplev.c | 6 ----- gcc/varasm.c | 35 +++++++----------------------- 22 files changed, 83 insertions(+), 136 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8c624ea..79cf6b0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,37 @@ +2004-02-23 Zack Weinberg + Kazu Hirata + + Remove -fwritable-strings. + * c-common.c (fix_string_type): Don't check + flag_writable_strings. + (fix_string_type): Likewise. + * c-opts.c (set_std_c89): Don't initialize + flag_writable_strings. + (set_std_c99): Likewise. + * common.opt (fwritable-strings): Remove. + * flags.h: Remove the external declaration of + flag_writable_strings. + * opts.c (common_handle_option) : + Remove. + * toplev.c (flag_writable_strings): Remove. + (f_options): Remove an entry for writable-strings. + * varasm.c (const_hash_1) : Don't check + flag_writable_strings. + (compare_constant) : Likewise. + (build_constant_desc): Likewise. + * config/darwin.c (machopic_select_section): Likewise. + * config/arm/arm.c (AOF_ASSEMBLER): Likewise. + * config/arm/pe.c (arm_pe_encode_section_info): Likewise. + * config/iq2000/iq2000.c (iq2000_select_section): Likewise. + * config/mips/mips.c (mips_select_section): Likewise. + (mips_encode_section_info): Likewise. + * config/pa/pa.c (pa_select_section): Likewise. + * config/pa/pa.h (TEXT_SPACE_P): Likewise. + * config/v850/v850.c (v850_select_section): Likewise. + * doc/invoke.texi (-fwritable-strings): Remove. + (-fno-const-strings): Don't mention -fwritable-strings. + * doc/trouble.texi: Don't mention -fwritable-strings. + 2003-02-23 Nathanael Nerode * doc/install.texi: Update for switch of boehm-gc to autoconf 2.57. diff --git a/gcc/c-common.c b/gcc/c-common.c index 2ebb915..3d9dbfa 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -1164,7 +1164,7 @@ fix_string_type (tree value) -Wwrite-strings says make the string constant an array of const char so that copying it to a non-const pointer will get a warning. For C++, this is the standard behavior. */ - if (flag_const_strings && ! flag_writable_strings) + if (flag_const_strings) { tree elements = build_type_variant (wide_flag ? wchar_type_node : char_type_node, @@ -1179,7 +1179,7 @@ fix_string_type (tree value) build_index_type (build_int_2 (nchars - 1, 0))); TREE_CONSTANT (value) = 1; - TREE_READONLY (value) = ! flag_writable_strings; + TREE_READONLY (value) = 1; TREE_STATIC (value) = 1; return value; } diff --git a/gcc/c-opts.c b/gcc/c-opts.c index c9b34db..b4f3851 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -1521,7 +1521,6 @@ set_std_c89 (int c94, int iso) flag_no_nonansi_builtin = iso; flag_isoc94 = c94; flag_isoc99 = 0; - flag_writable_strings = 0; } /* Set the C 99 standard (without GNU extensions if ISO). */ @@ -1534,7 +1533,6 @@ set_std_c99 (int iso) flag_iso = iso; flag_isoc99 = 1; flag_isoc94 = 1; - flag_writable_strings = 0; } /* Set the C++ 98 standard (without GNU extensions if ISO). */ diff --git a/gcc/common.opt b/gcc/common.opt index 8598d8c..cc7f218 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -738,10 +738,6 @@ fwrapv Common Assume signed arithmetic overflow wraps around -fwritable-strings -Common -Store strings in writable data section - fzero-initialized-in-bss Common Put zero initialized data in the bss section diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 7ae5312..c774f19 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -13948,8 +13948,7 @@ arm_encode_section_info (tree decl, rtx rtl, int first) /* This doesn't work with AOF syntax, since the string table may be in a different AREA. */ #ifndef AOF_ASSEMBLER - if (optimize > 0 && TREE_CONSTANT (decl) - && (!flag_writable_strings || TREE_CODE (decl) != STRING_CST)) + if (optimize > 0 && TREE_CONSTANT (decl)) SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1; #endif diff --git a/gcc/config/arm/pe.c b/gcc/config/arm/pe.c index 2d38d1f..702ea3e 100644 --- a/gcc/config/arm/pe.c +++ b/gcc/config/arm/pe.c @@ -213,8 +213,7 @@ arm_pe_encode_section_info (decl, rtl, first) int first ATTRIBUTE_UNUSED; { /* This bit is copied from arm_encode_section_info. */ - if (optimize > 0 && TREE_CONSTANT (decl) - && (!flag_writable_strings || TREE_CODE (decl) != STRING_CST)) + if (optimize > 0 && TREE_CONSTANT (decl)) SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1; /* Mark the decl so we can tell from the rtl whether the object is diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index fd5d8b6..667c21e 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -1215,8 +1215,7 @@ machopic_select_section (tree exp, int reloc, if (TREE_CODE (exp) == STRING_CST && ((size_t) TREE_STRING_LENGTH (exp) - == strlen (TREE_STRING_POINTER (exp)) + 1) - && ! flag_writable_strings) + == strlen (TREE_STRING_POINTER (exp)) + 1)) cstring_section (); else if ((TREE_CODE (exp) == INTEGER_CST || TREE_CODE (exp) == REAL_CST) && flag_merge_constants) diff --git a/gcc/config/iq2000/iq2000.c b/gcc/config/iq2000/iq2000.c index 90efc4b..55bda5f 100644 --- a/gcc/config/iq2000/iq2000.c +++ b/gcc/config/iq2000/iq2000.c @@ -2623,15 +2623,13 @@ iq2000_select_section (tree decl, int reloc ATTRIBUTE_UNUSED, { /* For embedded applications, always put an object in read-only data if possible, in order to reduce RAM usage. */ - if (((TREE_CODE (decl) == VAR_DECL - && TREE_READONLY (decl) && !TREE_SIDE_EFFECTS (decl) - && DECL_INITIAL (decl) - && (DECL_INITIAL (decl) == error_mark_node - || TREE_CONSTANT (DECL_INITIAL (decl)))) - /* Deal with calls from output_constant_def_contents. */ - || (TREE_CODE (decl) != VAR_DECL - && (TREE_CODE (decl) != STRING_CST - || !flag_writable_strings)))) + if ((TREE_CODE (decl) == VAR_DECL + && TREE_READONLY (decl) && !TREE_SIDE_EFFECTS (decl) + && DECL_INITIAL (decl) + && (DECL_INITIAL (decl) == error_mark_node + || TREE_CONSTANT (DECL_INITIAL (decl)))) + /* Deal with calls from output_constant_def_contents. */ + || TREE_CODE (decl) != VAR_DECL) readonly_data_section (); else data_section (); @@ -2640,15 +2638,13 @@ iq2000_select_section (tree decl, int reloc ATTRIBUTE_UNUSED, { /* For hosted applications, always put an object in small data if possible, as this gives the best performance. */ - if (((TREE_CODE (decl) == VAR_DECL - && TREE_READONLY (decl) && !TREE_SIDE_EFFECTS (decl) - && DECL_INITIAL (decl) - && (DECL_INITIAL (decl) == error_mark_node - || TREE_CONSTANT (DECL_INITIAL (decl)))) - /* Deal with calls from output_constant_def_contents. */ - || (TREE_CODE (decl) != VAR_DECL - && (TREE_CODE (decl) != STRING_CST - || !flag_writable_strings)))) + if ((TREE_CODE (decl) == VAR_DECL + && TREE_READONLY (decl) && !TREE_SIDE_EFFECTS (decl) + && DECL_INITIAL (decl) + && (DECL_INITIAL (decl) == error_mark_node + || TREE_CONSTANT (DECL_INITIAL (decl)))) + /* Deal with calls from output_constant_def_contents. */ + || TREE_CODE (decl) != VAR_DECL) readonly_data_section (); else data_section (); diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c index 88dca98..aba6639 100644 --- a/gcc/config/mips/mips.c +++ b/gcc/config/mips/mips.c @@ -7283,8 +7283,7 @@ mips_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) { if ((TARGET_EMBEDDED_PIC || TARGET_MIPS16) - && TREE_CODE (decl) == STRING_CST - && !flag_writable_strings) + && TREE_CODE (decl) == STRING_CST) /* For embedded position independent code, put constant strings in the text section, because the data section is limited to 64K in size. For mips16 code, put strings in the text section so that a PC @@ -7366,7 +7365,6 @@ mips_encode_section_info (tree decl, rtx rtl, int first) if (TARGET_MIPS16) { if (first && TREE_CODE (decl) == STRING_CST - && ! flag_writable_strings /* If this string is from a function, and the function will go in a gnu linkonce section, then we can't directly access the string. This gets an assembler error @@ -7393,8 +7391,7 @@ mips_encode_section_info (tree decl, rtx rtl, int first) SYMBOL_REF_FLAG (symbol) = 1; else if (TREE_CODE (decl) == FUNCTION_DECL) SYMBOL_REF_FLAG (symbol) = 0; - else if (TREE_CODE (decl) == STRING_CST - && ! flag_writable_strings) + else if (TREE_CODE (decl) == STRING_CST) SYMBOL_REF_FLAG (symbol) = 0; else SYMBOL_REF_FLAG (symbol) = 1; diff --git a/gcc/config/pa/pa.c b/gcc/config/pa/pa.c index 0f9a2db..e2074a1 100644 --- a/gcc/config/pa/pa.c +++ b/gcc/config/pa/pa.c @@ -9076,7 +9076,6 @@ pa_select_section (tree exp, int reloc, && !reloc) readonly_data_section (); else if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'c' - && !(TREE_CODE (exp) == STRING_CST && flag_writable_strings) && !reloc) readonly_data_section (); else diff --git a/gcc/config/pa/pa.h b/gcc/config/pa/pa.h index 3088425..b83acbc 100644 --- a/gcc/config/pa/pa.h +++ b/gcc/config/pa/pa.h @@ -1666,8 +1666,7 @@ do { \ && TREE_READONLY (DECL) && ! TREE_SIDE_EFFECTS (DECL) \ && (! DECL_INITIAL (DECL) || ! reloc_needed (DECL_INITIAL (DECL))) \ && !flag_pic) \ - || (TREE_CODE_CLASS (TREE_CODE (DECL)) == 'c' \ - && !(TREE_CODE (DECL) == STRING_CST && flag_writable_strings))) + || (TREE_CODE_CLASS (TREE_CODE (DECL)) == 'c')) #define FUNCTION_NAME_P(NAME) (*(NAME) == '@') diff --git a/gcc/config/v850/v850.c b/gcc/config/v850/v850.c index 08adab1..8337262 100644 --- a/gcc/config/v850/v850.c +++ b/gcc/config/v850/v850.c @@ -3399,13 +3399,6 @@ v850_select_section (tree exp, break; } } - else if (TREE_CODE (exp) == STRING_CST) - { - if (! flag_writable_strings) - readonly_data_section (); - else - data_section (); - } else readonly_data_section (); } diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3930fd4..875f7a5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2004-02-23 Zack Weinberg + Kazu Hirata + + * decl.c (cxx_init_decl_processing): Don't check + flag_writable_strings. + 2004-02-23 Andrew Pinski PR c++/14156 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 1db274e..6a4d6ef 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -3104,11 +3104,6 @@ cxx_init_decl_processing (void) /* Show we use EH for cleanups. */ using_eh_for_cleanups (); - - /* Maintain consistency. Perhaps we should just complain if they - say -fwritable-strings? */ - if (flag_writable_strings) - flag_const_strings = 0; } /* Generate an initializer for a function naming variable from diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 3a06239..b703dc3 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -166,8 +166,7 @@ in the following sections. -trigraphs -no-integrated-cpp -traditional -traditional-cpp @gol -fallow-single-precision -fcond-mismatch @gol -fsigned-bitfields -fsigned-char @gol --funsigned-bitfields -funsigned-char @gol --fwritable-strings} +-funsigned-bitfields -funsigned-char} @item C++ Language Options @xref{C++ Dialect Options,,Options Controlling C++ Dialect}. @@ -1210,17 +1209,6 @@ These options control whether a bit-field is signed or unsigned, when the declaration does not use either @code{signed} or @code{unsigned}. By default, such a bit-field is signed, because this is consistent: the basic integer types such as @code{int} are signed types. - -@item -fwritable-strings -@opindex fwritable-strings -Store string constants in the writable data segment and don't uniquize -them. This is for compatibility with old programs which assume they can -write into string constants. - -Writing into string constants is a very bad idea; ``constants'' should -be constant. - -This option is deprecated. @end table @node C++ Dialect Options @@ -1292,8 +1280,7 @@ been added for putting variables into BSS without making them common. Give string constants type @code{char *} instead of type @code{const char *}. By default, G++ uses type @code{const char *} as required by the standard. Even if you use @option{-fno-const-strings}, you cannot -actually modify the value of a string constant, unless you also use -@option{-fwritable-strings}. +actually modify the value of a string constant. This option might be removed in a future release of G++. For maximum portability, you should structure your code so that it works with diff --git a/gcc/doc/trouble.texi b/gcc/doc/trouble.texi index ce62c95..2af4525 100644 --- a/gcc/doc/trouble.texi +++ b/gcc/doc/trouble.texi @@ -431,17 +431,14 @@ string its argument points to. @cindex @code{sscanf}, and constant strings @cindex @code{fscanf}, and constant strings @cindex @code{scanf}, and constant strings -Another consequence is that @code{sscanf} does not work on some systems -when passed a string constant as its format control string or input. -This is because @code{sscanf} incorrectly tries to write into the string -constant. Likewise @code{fscanf} and @code{scanf}. +Another consequence is that @code{sscanf} does not work on some very +old systems when passed a string constant as its format control string +or input. This is because @code{sscanf} incorrectly tries to write +into the string constant. Likewise @code{fscanf} and @code{scanf}. -@opindex fwritable-strings -The best solution to these problems is to change the program to use +The solution to these problems is to change the program to use @code{char}-array variables with initialization strings for these -purposes instead of string constants. But if this is not possible, -you can use the @option{-fwritable-strings} flag, which directs GCC -to handle string constants the same way most C compilers do. +purposes instead of string constants. @item @code{-2147483648} is positive. diff --git a/gcc/flags.h b/gcc/flags.h index 626993f..81793a8 100644 --- a/gcc/flags.h +++ b/gcc/flags.h @@ -317,11 +317,6 @@ extern int flag_cse_skip_blocks; perform miscellaneous relatively-expensive optimizations. */ extern int flag_expensive_optimizations; -/* Nonzero for -fwritable-strings: - store string constants in data segment and don't uniquize them. */ - -extern int flag_writable_strings; - /* Nonzero means don't put addresses of constant functions in registers. Used for compiling the Unix kernel, where strange substitutions are done on the assembly output. */ diff --git a/gcc/opts.c b/gcc/opts.c index a83357b..a4267f8 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -1455,10 +1455,6 @@ common_handle_option (size_t scode, const char *arg, flag_wrapv = value; break; - case OPT_fwritable_strings: - flag_writable_strings = value; - break; - case OPT_fzero_initialized_in_bss: flag_zero_initialized_in_bss = value; break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b912032..f608919 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-02-23 Zack Weinberg + Kazu Hirata + + * gcc.dg/fwritable-strings-1.c: Remove. + 2004-02-23 Andrew Pinski PR c/14156 diff --git a/gcc/testsuite/gcc.dg/fwritable-strings-1.c b/gcc/testsuite/gcc.dg/fwritable-strings-1.c index 652a084..e69de29 100644 --- a/gcc/testsuite/gcc.dg/fwritable-strings-1.c +++ b/gcc/testsuite/gcc.dg/fwritable-strings-1.c @@ -1,18 +0,0 @@ -/* PR c/12818 */ -/* Origin: */ - -/* { dg-do run } */ -/* { dg-options "-fwritable-strings" } */ -/* { dg-error "-fwritable-strings is deprecated" "" { target *-*-* } 0 } */ - -extern void abort(void); - -char *names[] = {"alice", "bob", "john"}; - -int main (void) -{ - if (names[1][0] != 'b') - abort(); - - return 0; -} diff --git a/gcc/toplev.c b/gcc/toplev.c index 071fb5d..9e10d01 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -582,11 +582,6 @@ int flag_reduce_all_givs = 0; int flag_regmove = 0; -/* Nonzero for -fwritable-strings: - store string constants in data segment and don't uniquize them. */ - -int flag_writable_strings = 0; - /* Nonzero means don't put addresses of constant functions in registers. Used for compiling the Unix kernel, where strange substitutions are done on the assembly output. */ @@ -1076,7 +1071,6 @@ static const lang_independent_options f_options[] = {"prefetch-loop-arrays", &flag_prefetch_loop_arrays, 1 }, {"move-all-movables", &flag_move_all_movables, 1 }, {"reduce-all-givs", &flag_reduce_all_givs, 1 }, - {"writable-strings", &flag_writable_strings, 1 }, {"peephole", &flag_no_peephole, 0 }, {"force-mem", &flag_force_mem, 1 }, {"force-addr", &flag_force_addr, 1 }, diff --git a/gcc/varasm.c b/gcc/varasm.c index 806224d..061cbca 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -2029,16 +2029,8 @@ const_hash_1 (const tree exp) return real_hash (TREE_REAL_CST_PTR (exp)); case STRING_CST: - if (flag_writable_strings) - { - p = (char *) &exp; - len = sizeof exp; - } - else - { - p = TREE_STRING_POINTER (exp); - len = TREE_STRING_LENGTH (exp); - } + p = TREE_STRING_POINTER (exp); + len = TREE_STRING_LENGTH (exp); break; case COMPLEX_CST: @@ -2154,9 +2146,6 @@ compare_constant (const tree t1, const tree t2) return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2)); case STRING_CST: - if (flag_writable_strings) - return t1 == t2; - if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))) return 0; @@ -2359,10 +2348,7 @@ build_constant_desc (tree exp) struct constant_descriptor_tree *desc; desc = ggc_alloc (sizeof (*desc)); - if (flag_writable_strings && TREE_CODE (exp) == STRING_CST) - desc->value = exp; - else - desc->value = copy_constant (exp); + desc->value = copy_constant (exp); /* Create a string containing the label name, in LABEL. */ labelno = const_labelno++; @@ -2444,9 +2430,9 @@ maybe_output_constant_def_contents (struct constant_descriptor_tree *desc, /* Already output; don't do it again. */ return; - /* The only constants that cannot safely be deferred, assuming the - context allows it, are strings under flag_writable_strings. */ - if (defer && (TREE_CODE (exp) != STRING_CST || !flag_writable_strings)) + /* We can always defer constants as long as the context allows + doing so. */ + if (defer) { /* Increment n_deferred_constants if it exists. It needs to be at least as large as the number of constants actually referred to @@ -4486,7 +4472,7 @@ default_select_section (tree decl, int reloc, readonly = true; } else if (TREE_CODE (decl) == STRING_CST) - readonly = !flag_writable_strings; + readonly = true; else if (! (flag_pic && reloc)) readonly = true; @@ -4544,12 +4530,7 @@ categorize_decl_for_section (tree decl, int reloc, int shlib) if (TREE_CODE (decl) == FUNCTION_DECL) return SECCAT_TEXT; else if (TREE_CODE (decl) == STRING_CST) - { - if (flag_writable_strings) - return SECCAT_DATA; - else - return SECCAT_RODATA_MERGE_STR; - } + return SECCAT_RODATA_MERGE_STR; else if (TREE_CODE (decl) == VAR_DECL) { if (DECL_INITIAL (decl) == NULL -- 2.7.4