On 05/08/2012 04:13 PM, Jan Pokorný wrote: > When the cast is optimized out/target pointer type information lost, > it may be impossible for backend to recover it (think of > "struct foo *my_new_foo = malloc(sizeof(*my_new_foo))"). > > Losing such pointer type information can be wider issue (structs and > unions maybe), but this is the most exposed one and the patch tries > to be minimal in this regard and the impact seems to be minimal > too as usually type-correctness is followed. I expected that if both operands of the cast appear to be pointers, it is always OP_PTRCAST case, which is not true. So this version exchanges inequality test for "or". Beside being shorter, it covers such previously missed cases. Based on asserts I experimented with, OP_PTRCASTs are always captured by the condition implicitly (beside OP_CASTs with pointer-like operands). Signed-off-by: Jan Pokorný <pokorny_jan@xxxxxxxxx> --- simplify.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/simplify.c b/simplify.c index 8200584..bda4a5b 100644 --- a/simplify.c +++ b/simplify.c @@ -10,6 +10,7 @@ #include "expression.h" #include "linearize.h" #include "flow.h" +#include "symbol.h" /* Find the trivial parent for a phi-source */ static struct basic_block *phi_parent(struct basic_block *source, pseudo_t pseudo) @@ -667,6 +668,11 @@ static int simplify_cast(struct instruction *insn) orig_type = insn->orig_type; if (!orig_type) return 0; + + /* Keep casts with pointer on either side (not only case of OP_PTRCAST) */ + if (is_ptr_type(orig_type) || is_ptr_type(insn->type)) + return 0; + orig_size = orig_type->bit_size; size = insn->size; src = insn->src; -- 1.7.3.4 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html