summaryrefslogtreecommitdiffstats
path: root/gcc/tree-ssa-loop-niter.c
diff options
context:
space:
mode:
authorvries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>2011-06-16 17:57:08 +0000
committervries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>2011-06-16 17:57:08 +0000
commit8767ae9cc8f2181b37bb932cac7b4561de8cc5a2 (patch)
treecb98d10fa3dd18ae5bf610534fbf0c44fdd76650 /gcc/tree-ssa-loop-niter.c
parent43d05bf0404954b5997f7bb8ef8fbd211ce5b8b9 (diff)
downloadppe42-gcc-8767ae9cc8f2181b37bb932cac7b4561de8cc5a2.tar.gz
ppe42-gcc-8767ae9cc8f2181b37bb932cac7b4561de8cc5a2.zip
2011-06-16 Tom de Vries <tom@codesourcery.com>
PR target/45098 * tree-ssa-loop-niter.c (infer_loop_bounds_from_pointer_arith): Disallow NULL pointer for pointer arithmetic. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@175105 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-loop-niter.c')
-rw-r--r--gcc/tree-ssa-loop-niter.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index fa3ccc63f59..cf2f4556395 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -2875,6 +2875,16 @@ infer_loop_bounds_from_pointer_arith (struct loop *loop, gimple stmt)
low = lower_bound_in_type (type, type);
high = upper_bound_in_type (type, type);
+ /* In C, pointer arithmetic p + 1 cannot use a NULL pointer, and p - 1 cannot
+ produce a NULL pointer. The contrary would mean NULL points to an object,
+ while NULL is supposed to compare unequal with the address of all objects.
+ Furthermore, p + 1 cannot produce a NULL pointer and p - 1 cannot use a
+ NULL pointer since that would mean wrapping, which we assume here not to
+ happen. So, we can exclude NULL from the valid range of pointer
+ arithmetic. */
+ if (flag_delete_null_pointer_checks && int_cst_value (low) == 0)
+ low = build_int_cstu (TREE_TYPE (low), TYPE_ALIGN_UNIT (TREE_TYPE (type)));
+
record_nonwrapping_iv (loop, base, step, stmt, low, high, false, true);
}
OpenPOWER on IntegriCloud