From 99c383d614156d4f4cb0792b464711b35fdb1718 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 15 Apr 2012 13:19:32 +0200 Subject: [PATCH] avoid negative array indices In particular, restrict the domains of access functions to those values where the indices are non-negative. Signed-off-by: Sven Verdoolaege --- scan.cc | 6 +++++- tests/forward_substitution2.scop | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scan.cc b/scan.cc index 9a8e989..7ff48f3 100644 --- a/scan.cc +++ b/scan.cc @@ -920,7 +920,8 @@ __isl_give isl_map *PetScan::extract_access(Expr *expr) return NULL; } -/* Assign the affine expression "index" to the output dimension "pos" of "map" +/* Assign the affine expression "index" to the output dimension "pos" of "map", + * restrict the domain to those values that result in a non-negative index * and return the result. */ __isl_give isl_map *set_index(__isl_take isl_map *map, int pos, @@ -929,7 +930,10 @@ __isl_give isl_map *set_index(__isl_take isl_map *map, int pos, isl_map *index_map; int len = isl_map_dim(map, isl_dim_out); isl_id *id; + isl_set *domain; + domain = isl_pw_aff_nonneg_set(isl_pw_aff_copy(index)); + index = isl_pw_aff_intersect_domain(index, domain); index_map = isl_map_from_range(isl_set_from_pw_aff(index)); index_map = isl_map_insert_dims(index_map, isl_dim_out, 0, pos); index_map = isl_map_add_dims(index_map, isl_dim_out, len - pos - 1); diff --git a/tests/forward_substitution2.scop b/tests/forward_substitution2.scop index c839953..dd0a054 100644 --- a/tests/forward_substitution2.scop +++ b/tests/forward_substitution2.scop @@ -3,12 +3,15 @@ arrays: - context: '{ : }' extent: '{ N[] }' element_type: int + element_size: 4 - context: '{ : }' extent: '{ a[i0] : i0 >= 0 and i0 <= 9 }' element_type: int + element_size: 4 - context: '{ : }' extent: '{ c[] }' element_type: int + element_size: 4 statements: - line: 5 domain: '{ S_0[] }' @@ -48,7 +51,7 @@ statements: operation: = arguments: - type: access - relation: '{ [S_2[] -> [i0]] -> a[i0] }' + relation: '{ [S_2[] -> [i0]] -> a[i0] : i0 >= 0 }' read: 0 write: 1 arguments: -- 2.11.4.GIT