re PR c/12818 (-fwritable strings triggers bad code generation)
PR c/12818 * varasm.c (const_hash_1) <STRING_CST>: Use the address to compute the hash value if flag_writable_strings. (compare_constant) <STRING_CST>: Compare the addresses if flag_writable_strings. (build_constant_desc): Do not copy the expression for a STRING_CST if flag_writable_strings. From-SVN: r76958
This commit is contained in:
parent
7dcc98e25c
commit
5e9295fa05
|
@ -1,3 +1,13 @@
|
||||||
|
2004-01-30 Eric Botcazou <ebotcazou@libertysurf.fr>
|
||||||
|
|
||||||
|
PR c/12818
|
||||||
|
* varasm.c (const_hash_1) <STRING_CST>: Use the
|
||||||
|
address to compute the hash value if flag_writable_strings.
|
||||||
|
(compare_constant) <STRING_CST>: Compare the addresses
|
||||||
|
if flag_writable_strings.
|
||||||
|
(build_constant_desc): Do not copy the expression for a
|
||||||
|
STRING_CST if flag_writable_strings.
|
||||||
|
|
||||||
2004-01-30 Jan Hubicka <jh@suse.cz>
|
2004-01-30 Jan Hubicka <jh@suse.cz>
|
||||||
|
|
||||||
* alloc-pool.c: Include hashtab.h
|
* alloc-pool.c: Include hashtab.h
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
2004-01-30 Eric Botcazou <ebotcazou@libertysurf.fr>
|
||||||
|
|
||||||
|
* gcc.dg/fwritable-strings-1.c: New test.
|
||||||
|
|
||||||
2004-01-30 Eric Botcazou <ebotcazou@libertysurf.fr>
|
2004-01-30 Eric Botcazou <ebotcazou@libertysurf.fr>
|
||||||
|
|
||||||
* gcc.c-torture/compile/20040130-1.c: New test.
|
* gcc.c-torture/compile/20040130-1.c: New test.
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
/* PR c/12818 */
|
||||||
|
/* Origin: <fnf@ninemoons.com> */
|
||||||
|
|
||||||
|
/* { dg-do run } */
|
||||||
|
/* { dg-options "-fwritable-strings" } */
|
||||||
|
|
||||||
|
extern void abort(void);
|
||||||
|
|
||||||
|
char *names[] = {"alice", "bob", "john"};
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
if (names[1][0] != 'b')
|
||||||
|
abort();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
18
gcc/varasm.c
18
gcc/varasm.c
|
@ -2057,7 +2057,7 @@ struct rtx_const GTY(())
|
||||||
|
|
||||||
/* Uniquize all constants that appear in memory.
|
/* Uniquize all constants that appear in memory.
|
||||||
Each constant in memory thus far output is recorded
|
Each constant in memory thus far output is recorded
|
||||||
in `const_hash_table'. */
|
in `const_desc_table'. */
|
||||||
|
|
||||||
struct constant_descriptor_tree GTY(())
|
struct constant_descriptor_tree GTY(())
|
||||||
{
|
{
|
||||||
|
@ -2104,9 +2104,18 @@ const_hash_1 (const tree exp)
|
||||||
return real_hash (TREE_REAL_CST_PTR (exp));
|
return real_hash (TREE_REAL_CST_PTR (exp));
|
||||||
|
|
||||||
case STRING_CST:
|
case STRING_CST:
|
||||||
|
if (flag_writable_strings)
|
||||||
|
{
|
||||||
|
p = (char *) &exp;
|
||||||
|
len = sizeof exp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
p = TREE_STRING_POINTER (exp);
|
p = TREE_STRING_POINTER (exp);
|
||||||
len = TREE_STRING_LENGTH (exp);
|
len = TREE_STRING_LENGTH (exp);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COMPLEX_CST:
|
case COMPLEX_CST:
|
||||||
return (const_hash_1 (TREE_REALPART (exp)) * 5
|
return (const_hash_1 (TREE_REALPART (exp)) * 5
|
||||||
+ const_hash_1 (TREE_IMAGPART (exp)));
|
+ const_hash_1 (TREE_IMAGPART (exp)));
|
||||||
|
@ -2221,7 +2230,7 @@ compare_constant (const tree t1, const tree t2)
|
||||||
|
|
||||||
case STRING_CST:
|
case STRING_CST:
|
||||||
if (flag_writable_strings)
|
if (flag_writable_strings)
|
||||||
return 0;
|
return t1 == t2;
|
||||||
|
|
||||||
if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
|
if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2425,6 +2434,9 @@ build_constant_desc (tree exp)
|
||||||
struct constant_descriptor_tree *desc;
|
struct constant_descriptor_tree *desc;
|
||||||
|
|
||||||
desc = ggc_alloc (sizeof (*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. */
|
/* Create a string containing the label name, in LABEL. */
|
||||||
|
@ -2466,7 +2478,7 @@ build_constant_desc (tree exp)
|
||||||
If DEFER is nonzero, this constant can be deferred and output only
|
If DEFER is nonzero, this constant can be deferred and output only
|
||||||
if referenced in the function after all optimizations.
|
if referenced in the function after all optimizations.
|
||||||
|
|
||||||
The const_hash_table records which constants already have label strings. */
|
`const_desc_table' records which constants already have label strings. */
|
||||||
|
|
||||||
rtx
|
rtx
|
||||||
output_constant_def (tree exp, int defer)
|
output_constant_def (tree exp, int defer)
|
||||||
|
|
Loading…
Reference in New Issue