From 5460e4b2da7d9a0ccebeaef114eb26604b04ef4d Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 22 May 2013 11:52:49 +0200 Subject: [PATCH] isl_basic_map_foreach_lexopt: properly merge partial empty solutions b9f95db (isl_basic_map_foreach_lexopt: properly merge partial solutions, Wed Mar 20 09:55:50 2013 +0100) fixed the merging of partial non-empty solutions, but did not take into account that partial solutions may be empty. If the partial solutions are empty, then M is NULL and we cannot dereference it. Note that the new test case only triggers on top of d7e5adb (isl_tab_basic_map_partial_lexopt: better exploit partial solution cache, Tue Mar 12 17:25:04 2013 +0100) in the master branch. Reported-by: Tomofumi Yuki Signed-off-by: Sven Verdoolaege --- isl_tab_pip.c | 12 +++++++++--- isl_test.c | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/isl_tab_pip.c b/isl_tab_pip.c index d5ed654..6f4a2a7 100644 --- a/isl_tab_pip.c +++ b/isl_tab_pip.c @@ -124,6 +124,8 @@ struct isl_context_lex { * "M" describes the solution in terms of the dimensions of "dom". * The number of columns of "M" is one more than the total number * of dimensions of "dom". + * + * If "M" is NULL, then there is no solution on "dom". */ struct isl_partial_sol { int level; @@ -322,11 +324,15 @@ static void sol_pop(struct isl_sol *sol) isl_basic_set_free(partial->next->dom); partial->next->dom = bset; M = partial->next->M; - M = isl_mat_drop_cols(M, M->n_col - n, n); - partial->next->M = M; + if (M) { + M = isl_mat_drop_cols(M, M->n_col - n, n); + partial->next->M = M; + if (!M) + goto error; + } partial->next->level = sol->level; - if (!bset || !M) + if (!bset) goto error; sol->partial = partial->next; diff --git a/isl_test.c b/isl_test.c index 7c7b695..951ac75 100644 --- a/isl_test.c +++ b/isl_test.c @@ -1534,6 +1534,20 @@ void test_lexmin(struct isl_ctx *ctx) assert(isl_map_is_equal(map, map2)); isl_map_free(map); isl_map_free(map2); + + /* Check that empty pieces are properly combined. */ + str = "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and " + "2N-6<=x=N and a>=x+1 }"; + map = isl_map_read_from_str(ctx, str); + map = isl_map_lexmin(map); + str = "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and " + "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and " + "x >= 4 }"; + map2 = isl_map_read_from_str(ctx, str); + assert(isl_map_is_equal(map, map2)); + isl_map_free(map); + isl_map_free(map2); } struct must_may { -- 2.7.4