From c911d964e5c58cbee2131416fcb6e666df2e092c Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Thu, 6 Aug 2015 19:46:46 +0200 Subject: [PATCH] Make pass-by-reference explicit by using pointers GMP's mpz_t automatically decays to pointer and IMath's mp_int is a pointer, therefore changing them in a function body always also changes the argument of the function's caller. With an isl_int implementation without pointer semantics (as in imath-32) this is not the case and the value change is not visible outside of the function. The parameters g, fl and fu of function construct_test_ineq are allocated and free'd by its caller, hence we pass pointers to these locations instead of the values themselves. Otherwise, the values may get promoted to a big representation inside the function and the memory allocated in that conversion would not get freed, resulting in a memory leak. Similarly, if the function is passed in an integer in big representation (in g), then double frees can occur as memory is freed first inside the function and then later on outside again. 8528f07 (Make pass-by-reference explicit by using pointers, Tue May 26 15:02:33 2015 +0200) and a1e44f0 (Make pass-by-reference explicit by using pointer, Tue Jun 30 16:59:45 2015 +0200) fix similar issues in isl_int_gcdext and row_cmp. Signed-off-by: Tobias Grosser Signed-off-by: Sven Verdoolaege --- isl_map_simplify.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/isl_map_simplify.c b/isl_map_simplify.c index 0e749073..cb39b704 100644 --- a/isl_map_simplify.c +++ b/isl_map_simplify.c @@ -3364,23 +3364,23 @@ static int div_find_coalesce(struct isl_basic_map *bmap, int *pairs, * f_l e_u + f_u e_l + f_l - 1 + f_u - 1 + 1 >= f_u f_l g */ static void construct_test_ineq(struct isl_basic_map *bmap, int i, - int l, int u, isl_int *ineq, isl_int g, isl_int fl, isl_int fu) + int l, int u, isl_int *ineq, isl_int *g, isl_int *fl, isl_int *fu) { unsigned dim; dim = isl_space_dim(bmap->dim, isl_dim_all); - isl_int_gcd(g, bmap->ineq[l][1 + dim + i], bmap->ineq[u][1 + dim + i]); - isl_int_divexact(fl, bmap->ineq[l][1 + dim + i], g); - isl_int_divexact(fu, bmap->ineq[u][1 + dim + i], g); - isl_int_neg(fu, fu); - isl_seq_combine(ineq, fl, bmap->ineq[u], fu, bmap->ineq[l], + isl_int_gcd(*g, bmap->ineq[l][1 + dim + i], bmap->ineq[u][1 + dim + i]); + isl_int_divexact(*fl, bmap->ineq[l][1 + dim + i], *g); + isl_int_divexact(*fu, bmap->ineq[u][1 + dim + i], *g); + isl_int_neg(*fu, *fu); + isl_seq_combine(ineq, *fl, bmap->ineq[u], *fu, bmap->ineq[l], 1 + dim + bmap->n_div); - isl_int_add(ineq[0], ineq[0], fl); - isl_int_add(ineq[0], ineq[0], fu); + isl_int_add(ineq[0], ineq[0], *fl); + isl_int_add(ineq[0], ineq[0], *fu); isl_int_sub_ui(ineq[0], ineq[0], 1); - isl_int_mul(g, g, fl); - isl_int_mul(g, g, fu); - isl_int_sub(ineq[0], ineq[0], g); + isl_int_mul(*g, *g, *fl); + isl_int_mul(*g, *g, *fu); + isl_int_sub(ineq[0], ineq[0], *g); } /* Remove more kinds of divs that are not strictly needed. @@ -3433,7 +3433,7 @@ static struct isl_basic_map *drop_more_redundant_divs( if (!isl_int_is_neg(bmap->ineq[u][1 + dim + i])) continue; construct_test_ineq(bmap, i, l, u, - vec->el, g, fl, fu); + vec->el, &g, &fl, &fu); res = isl_tab_min(tab, vec->el, bmap->ctx->one, &g, NULL, 0); if (res == isl_lp_error) -- 2.11.4.GIT