From 47520e66c74dc525f50b3572b15b50215524e923 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 2 May 2014 11:42:50 +0200 Subject: [PATCH] isl_basic_set_{coefficients,solutions}: handle obviously empty input We already specifically handle this case in isl_set_coefficients and isl_set_solutions, but if isl_basic_set_coefficients or isl_basic_set_solutions is called directly, we would return a meaningless result. Signed-off-by: Sven Verdoolaege --- isl_farkas.c | 10 +++++++++ isl_test.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/isl_farkas.c b/isl_farkas.c index f0483521..ca523649 100644 --- a/isl_farkas.c +++ b/isl_farkas.c @@ -212,6 +212,11 @@ static __isl_give isl_basic_set *rational_universe(__isl_take isl_space *space) * to coefficients (shift == 1) and we drop the extra dimension when going * in the opposite direction (shift == -1). "dim" is the space in which * the dual should be created. + * + * If "bset" is (obviously) empty, then the way this emptiness + * is represented by the constraints does not allow for the application + * of the standard farkas algorithm. We therefore handle this case + * specifically and return the universe basic set. */ static __isl_give isl_basic_set *farkas(__isl_take isl_space *space, __isl_take isl_basic_set *bset, int shift) @@ -220,6 +225,11 @@ static __isl_give isl_basic_set *farkas(__isl_take isl_space *space, isl_basic_set *dual = NULL; unsigned total; + if (isl_basic_set_plain_is_empty(bset)) { + isl_basic_set_free(bset); + return rational_universe(space); + } + total = isl_basic_set_total_dim(bset); dual = isl_basic_set_alloc_space(space, bset->n_eq + bset->n_ineq, diff --git a/isl_test.c b/isl_test.c index 57bae2e8..a1410d54 100644 --- a/isl_test.c +++ b/isl_test.c @@ -4903,9 +4903,78 @@ static int test_compute_divs(isl_ctx *ctx) } struct { + const char *set; + const char *dual; +} coef_tests[] = { + { "{ rat: [i] : 0 <= i <= 10 }", + "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" }, + { "{ rat: [i] : FALSE }", + "{ rat: coefficients[[cst] -> [a]] }" }, + { "{ rat: [i] : }", + "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" }, +}; + +struct { + const char *set; + const char *dual; +} sol_tests[] = { + { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }", + "{ rat: [i] : 0 <= i <= 10 }" }, + { "{ rat: coefficients[[cst] -> [a]] : FALSE }", + "{ rat: [i] }" }, + { "{ rat: coefficients[[cst] -> [a]] }", + "{ rat: [i] : FALSE }" }, +}; + +/* Test the basic functionality of isl_basic_set_coefficients and + * isl_basic_set_solutions. + */ +static int test_dual(isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(coef_tests); ++i) { + int equal; + isl_basic_set *bset1, *bset2; + + bset1 = isl_basic_set_read_from_str(ctx, coef_tests[i].set); + bset2 = isl_basic_set_read_from_str(ctx, coef_tests[i].dual); + bset1 = isl_basic_set_coefficients(bset1); + equal = isl_basic_set_is_equal(bset1, bset2); + isl_basic_set_free(bset1); + isl_basic_set_free(bset2); + if (equal < 0) + return -1; + if (!equal) + isl_die(ctx, isl_error_unknown, + "incorrect dual", return -1); + } + + for (i = 0; i < ARRAY_SIZE(sol_tests); ++i) { + int equal; + isl_basic_set *bset1, *bset2; + + bset1 = isl_basic_set_read_from_str(ctx, sol_tests[i].set); + bset2 = isl_basic_set_read_from_str(ctx, sol_tests[i].dual); + bset1 = isl_basic_set_solutions(bset1); + equal = isl_basic_set_is_equal(bset1, bset2); + isl_basic_set_free(bset1); + isl_basic_set_free(bset2); + if (equal < 0) + return -1; + if (!equal) + isl_die(ctx, isl_error_unknown, + "incorrect dual", return -1); + } + + return 0; +} + +struct { const char *name; int (*fn)(isl_ctx *ctx); } tests [] = { + { "dual", &test_dual }, { "dependence analysis", &test_flow }, { "val", &test_val }, { "compute divs", &test_compute_divs }, -- 2.11.4.GIT