Hi!
tree_ssa_useless_type_conversion_1 is stripping away
the cast from
const char *a = "Foo";
*((char *)&a[2]) = 0;
because
/* Pointers and references are equivalent once we get to GENERIC,
so strip conversions that just switch between them. */
else if (POINTER_TYPE_P (inner_type)
&& POINTER_TYPE_P (outer_type)
&& TYPE_REF_CAN_ALIAS_ALL (inner_type)
== TYPE_REF_CAN_ALIAS_ALL (outer_type)
&& lang_hooks.types_compatible_p (TREE_TYPE (inner_type),
TREE_TYPE (outer_type)))
return true;
triggers (this is C).
(gdb) call debug_tree(inner_type)
<pointer_type 0x4015821c
type <integer_type 0x401581b0 char readonly QI
size <integer_cst 0x40141210 constant invariant 8>
unit size <integer_cst 0x40141228 constant invariant 1>
align 8 symtab 0 alias set -1 precision 8 min <integer_cst
0x40141270 -128> max <integer_cst 0x401412d0 127>
pointer_to_this <pointer_type 0x4015821c>>
unsigned SI
size <integer_cst 0x40141408 type <integer_type 0x40149288
bit_size_type> constant invariant 32>
unit size <integer_cst 0x40141198 type <integer_type 0x4014921c
unsigned int> constant invariant 4>
align 32 symtab 0 alias set -1
pointer_to_this <pointer_type 0x4015857c>>
(gdb) call debug_tree(outer_type)
<pointer_type 0x40156bd0
type <integer_type 0x401493cc char public QI
size <integer_cst 0x40141210 constant invariant 8>
unit size <integer_cst 0x40141228 constant invariant 1>
align 8 symtab 0 alias set -1 precision 8 min <integer_cst
0x40141270 -128> max <integer_cst 0x401412d0 127>
pointer_to_this <pointer_type 0x40156bd0>>
unsigned SI
size <integer_cst 0x40141408 type <integer_type 0x40149288
bit_size_type> constant invariant 32>
unit size <integer_cst 0x40141198 type <integer_type 0x4014921c
unsigned int> constant invariant 4>
align 32 symtab 0 alias set -1>
Further, because
int
c_types_compatible_p (tree x, tree y)
{
return comptypes (TYPE_MAIN_VARIANT (x), TYPE_MAIN_VARIANT (y));
}
comptypes for TYPE_MAIN_VARIANT (char) and TYPE_MAIN_VARIANT (const char)
returns true.
Please someone who knows the type system fix this.
Thanks,
Richard.
--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/