aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorJan Pokorný <pokorny_jan@seznam.cz>2012-05-10 03:07:47 -0700
committerChristopher Li <sparse@chrisli.org>2012-05-10 03:07:47 -0700
commit955cd225d2e3ee708e20de825eca82c8797897fd (patch)
tree810055d62f0206440dc2132b69d109ae0186efb4
parent695dd9d068dd2316b92706d174df9e30c1e71dcf (diff)
downloadsparse-dev-955cd225d2e3ee708e20de825eca82c8797897fd.tar.gz
simplify: conservative handling of casts with pointers
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@seznam.cz> Signed-off-by: Christopher Li <sparse@chrisli.org>
-rw-r--r--simplify.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/simplify.c b/simplify.c
index 82005849..bda4a5b4 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;